android studio issues, I can't open new activity with java - android-studio

when I open a new activity, the android studio allows me to write on Kotlin only, I want java, and I don't know the solution

This will might be work for you.
Clear Cache
First go to Build -> Clean Project. (Clears your Build Folders)
Still not working the solution do below step :
File -> Invalidate Caches / Restart
And still not working the remove your .gradle directory from the root of your project. It contains some Gradle cache files.

Related

Android Studio is syncing multiple projects at once

I have a Kotlin Multiplatform Project which contains an android library target. That library is imported to a separate android app project:
// settings.gradle.kts
include ":sharedLib"
project(":sharedLib").projectDir = file("../path/to/sharedLib")
Whenever I sync my app project in Android studio both the app and sharedLib projects sync in parallel. I am pretty sure this is some IDE setting i fluffed up when debugging source resolution with the sharedLib a while back.
Any ideas what AS settings i might have messed up? I actually removed AS and reset the configuration and yet I am dealing with seeing dual syncing.
Turns out it was some config stored in my project's .idea directory. Cleared it and everything is happy again.

How to view top-level gradle file in Android Studio?

I my Project tab I'm using the "Android" mode which conveniently groups all Gradle scripts together. I can only see the build.gradle files for the modules though, not the top-level build-gradle. Is there a way to list the top-level build.gradle here as well?
Look for the one labeled Project: [project name without the brackets]:
If you can't see it, it most likely doesn't exist (or Android Studio doesn't see it). Make sure it exists, and if it does, invalidate caches and restart*. If it doesn't, create it.
* A lot of issues related to Android Studio can be fixed this way. If the gradle file exists, but Android Studio isn't seeing it, invalidate the caches and see if that fixes it

Android studio suspended on indexing

When i run android studio it freeze on indexing and show me message:
indexing suspended (context: Gradle Sync)
it take more then 42 min and still show me this message i can't stop process and almost every thing is disable
Solutions I've tried
1- enable offline mode
2- select local gradle
3- invalidate caches/ Restart
but no one of this is solve my problem .
I've solved closing project (Menu File -> Close Project) and reopening it selecting his build.gradle.
Hope that helps
In my case, syncing the project with file system helped. But the project uses react-native and many gradle modules are located in the node_modules folder which could be updated by yarn/npm.

Android Studio download gradle takes forever

Everytime an imported project requires a specific version of gradle I don't have, it starts to sync. At this time, I close Android Studio, connect to vpn, and reopen Android Studio to sync gradle; however, sync never ends. Then I go to .gradle/wrapper/dists/gradle-xxx-all and nothing is downloaded (zip.part 0Kb). When I connect to vpn I can access gradle.org and download manually. Is this a bug with Android Studio or gradle?
There are many similar questions and most are solved by manually downloading the zip package. None solve the problem completely, though.
Follow below step to set automatically gradle sync in your android studio.
File -> Settings -> Build,Execution,Deployment ->Build tools -> gradle ->
check Use Default gradle wrapper(recommended) radiobutton.
Also follow below step to restart your android studio for invalid cache restart.
File > Invalidate Caches/Restart (you can also manually remove the cache at ~/Library/Caches/{yourIDEName} and restart the IDE)
Then save settings and rebuild your project.
Edit: See Android 1.5 Gradle Sync never completes to get more idea.
I hope its helps you.

AndroidStudio doesn't recognize R

I am teaching android app programming at a highschool. I found Eclipse to fragile so we are now trying out Android Studio. But a couple of students get that Android Studio with R. in red font, showing that it is not recognized.
This happened for example when the student copied the contents of my files.
It sometimes happens when you open a proyect from other sources. Just Synchronize it or press Ctrl-Alt-Y.
R.java file issues : 1) check the naming convention of images in drawable folder with size.
2) check the style of your application
In your case it may be missing style .. So upadate the style in value folder as per application .
The most common reason for this error is bad XML coding. For example using android:src="#drawable#drawable/picture" in ImageView will give you R error as it will not let R.Java file to build. Its hard to trace such errors as XML file will not show any error.
Also take a look if your resources are of good quality!
Hope it helps! Cheers
Build -> Clean Project
Tools -> Android -> Sync Project with Gradle Files
and all OK!
Try adding the following:
android.enableAapt2=false
to gradle.properties and Refresh:
You can also do the following: Clean Project and Sync Project with Gradle Files.
try importing your project :
To migrate existing Android projects, simply import them using Android Studio:
In Android Studio, close any projects currently open. You should see the Welcome to Android Studio window.
Click Import Non-Android Studio project.
Locate the project you exported from Eclipse, expand it, select the build.gradle file and click OK.
In the following dialog, leave Use gradle wrapper selected and click OK. (You do not need to specify the Gradle home.)
Android Studio properly updates the project structure and creates the appropriate Gradle build file.
First if the existing project was developed in eclipse you need to import the project and then check what are the error. If your students are coping codes from your project then after coping the codes they need to clean and sync the project. If still your problem not solved try this in android studio :-
File/invalidate caches/restart.
Hope it helps you :)
Especially, for regeneration of R.Java file.
If you have tried all these options:
Clean Project
Rebuild Project
Invalidate Caches / Restart
deleted .gradle folder
deleted .idea folder
deleted app/build/generated folder
checked your xml files
checked your drawables and strings
and still face problem then check your classpath dependency in your Project Gradle Scripts and if it's, this:
classpath 'com.android.tools.build:gradle:3.3.2'
then downgrade it to, this:
classpath 'com.android.tools.build:gradle:3.2.1'
clean and rebuild it will sync your project.
I had the same issue, and the lint gave me a hand...
If you're using lint, it can help too.
In gradle.build(Module:app) add the lintOptions sub-element in android element as shown below, then lint will fix it for you!!.
android {
lintOptions {
abortOnError false
}
}
I hope it helps!!

Resources