Save Gradle JDK in AndroidStudio BumbleBee between runs - android-studio

In AndroidStudio BumbleBee, there does not appear to be a way to configure the Gradle JDK that persists between full builds of the target app. Our app requires JDK 8 and Gradle requires JDK 11...
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
We develop our Cordova webapp (JS/CSS) on Mac for desktop first and then port to mobile. We do full builds, not incrementals.
Changing org.gradle.java.home does not work and might be too late as the JDK is already launched to run Gradle and parse org.gradle.java.home.
Changing JAVA_HOME sets the JDK for both our app and Gradle... and all other projects that use Java.
Chaning the IDE settings can be done manually... each full Cordova 11 build and launch of AndroidStudio. Here is how we have to set the Gradle JDK in AndroidStudio preferences... every time we launch Android Studio. Looking for a way to set the Gradle JDK in the IDE that will be honored between runs...
The dropdown includes the embedded JDK 11 that comes with AndroidStudio. This needs to be selected for the Gradle JDK to successfully build our app. Here is the dropdown...
Tried starting AndroidStudio from the commandline, where env variables can be set just for the launched process...
$ JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home" open "/Applications/Android Studio.app"
If there are no options in BumbleBee, are there plans for such support in later releases of Android Studio.

Related

How can I use gradle installed in WSL alongside Android Studio installed on Windows

I've recently had to start developing a Micronaut project in Android Studio instead of IntelliJ IDEA Ultimate. I'd assumed that because they share the same base this would be fine but when I load up my project I get this (the project is held in the wsl filesystem and all development has been using WSL with IDEA):
14:07 Project [name] is using the following JDK location when running Gradle:
//wsl$/Ubuntu-22.04/usr/lib/jvm/java-11-openjdk-amd64
Using different JDK locations on different processes might cause Gradle to
spawn multiple daemons, for example, by executing Gradle tasks from a terminal
while using Android Studio.
More info...
Select a JDK
Do not show this warning again
It's unclear why this is happening, when I click 'Select a JDK', what is selected is the JDK installed on WSL that IntelliJ is using, likewise it is pointed at the same directory where my gradle properties is kept.
I'm not sure where to go with this, my guess would be maybe Android Studio is trying to run a gradle or java instance that's not the WSL one (I think it installs it's own alongside) and that's the issue but the settings would imply otherwise. Does anyone know what might be happening?
Thanks!

Gradle Sync Failed in Android Studio 3.6 Cause invalid type code :85

I just update my Android Studio from version 3.5.3 to 3.6, now I open any project I see this error and gradle doesn't sync
I was having the same issue. I solved it by changing the JDK version I was using which was JDK 13.
Go to File -> Project Structure.
On the left side, click on SDK Location and go to JDK Location.
Change it to the Embedded JDK that comes with Android Studio.
Click on OK.
I found out that some people might use Android 4.0 with Java 14 and Gradle 6.1.1 like me. And they are not supported for each other, so just update Gradle to 6.5.1; it will solve the problem. To update Gradle, click in the Android Studio tab: File -> Project Structure -> Project. Then, change the Gradle version to 6.5.1.
Thanks, it was very helpfull!
Here's what I did to solve the issue with JDK 11 + Android 4.0.
Follow Tran's answer (https://stackoverflow.com/a/62967378/5359328) and upgrade to Gradle 6.5.1.
Build project. It still shows the same error.
Change JDK to 8 in Project Structure, build. It's successful.
Change JDK back to 11 in Project Structure, build. It's successful again.

Android Studio can't open project

I've recently get update notification of android studio 2.3, after the update it's not opening any project and throwing error:
[plugin: com.darkklord.gradle.metric.core]
after downgrading and reinstalling i still have this issue, can anyone please help me on this topic ?
Download latest plugin from here: https://plugins.jetbrains.com/plugin/9197-android-gradle-metrics--checkstyle
Install Plugin manually from disk.
Restart Android Studio (The error will still occur)
Remove plugin in IDE.
Restart
You might also uninstall the refrenzed plugins Checkstyle and PMD
You need to change your dependency
classpath 'com.android.tools.build:gradle:3.1.0'
Sometimes you need to change name of project manually(look at AndroidStudioProjects folder) that you opened lastly.
After changing name, android studio will show all projects,
open one of them,
in file menu,
click open button,
then open your desire project (or change its name to its previous name)
change build:gradle plugin to:
classpath 'com.android.tools.build:gradle:3.3.2'
(in app gradle file)
I made sure that my Gradle version was compatible with my android gradle plug in. In my case I was using Gradle 6.0.1 and when I changed my android gradle plug in to version 3.5.3 the problem went away.
Project Structure----->> Project ------>> Android Gradle plug in version 3.5.3.
[https://docs.gradle.org/6.0.1/release-notes.html
[Java 14 and later versions are not yet supported.
Compatibility Notes
A Java version between 8 and 13 is required to execute Gradle.
Java 6 and 7 can still be used for compilation and forked test execution. Just like Gradle 5.x, any supported version of Java can be used for compile or test.
This version of Gradle is tested with
-------->>>>>>>>Android Gradle Plugin 3.4, 3.5 and 3.6
Kotlin 1.3.21 through 1.3.50
Other versions may or may not work.]]]]
I hope this helps

Run Android Studio with Java 8

Since a plugin for IntelliJ (Upsource) requires Java 8 I'd like to run my Android Studio with Java 8 on a Mac.
I could setup JAVA_HOME and start Android Studio from terminal but this is very inconvenient. I'd like to start Android Studio from the OSX UI.
I did not find a way how to specify the JAVA_HOME with Android Studio settings. Moreover this link (https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under) says nothing about Android Studio.
Does anyone know where to configure the Runtime-JDK/JRE for Android Studio 2.1 on OSX without setting any JAVA_HOME?
From http://tools.android.com/tech-docs/configuration
export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk
You can also have a look here: http://tools.android.com/tech-docs/configuration/osx-jdk it explains how to set the jre for running android-studio and the jdk for your android project.
In short, you can in a terminal:
export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk
open /Applications/Android\ Studio.app
And it will launch android_studio with the jdk8
EDIT: from comment #Soccertrash
You can persist the STUDIO_JDK variable via launchctl:
launchctl setenv STUDIO_JDK /Library/Java/JavaVirtualMachines/jdk<version>

How to set Java SDK path in AndroidStudio?

I had Java 1.7.0_21 installed and I installed 1.7.0_45 today after uninstalling the previous version. Now Android Studio has stopped compiling projects and says that it cant locate the 1.7.0_21 folder. How can I set the new path for Java SDK? I have changed the environment variables also but didn't work.
Up to Android Studio 4.2
Go to File > Project Structure > SDK Location. The third field is "JDK Location" where you can set it. This will set it for the current project.
To set the default for new projects, go to File > Other Settings > Default Project Structure > SDK Location and set the "JDK Location".
Android Studio Arctic Fox (2020.3.1)
In the Canary 14 of Android Studio Arctic Fox (2020.3.1), the JDK Location setting is moved to:
Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK
Older Versions
Go to File > Project Structure > [Platform Settings] > SDKs. You'll need to either update you current SDK configuration to use the new directory, or define a new one and then change your project's settings to use the new one. This will set it for the current project.
To set the default for new projects, go to File > Other Settings > Structure for New Projects > [Platform Settings] > SDKs and set the SDK to use when creating a new project.
Go to File> Project Structure (or press Ctrl+Alt+Shift+S),
A popup will open now go to SDK Location Tab you will find JDK Location there refer this image to be more clear.
I tried updating all of my SDKs by just going into the Project Structure > Platform Settings > SDKs and changing the Java SDK, but that didn't work, so I had to recreate the configurations from scratch.
Here's how to create your SDKs with the latest Java:
In Project Structure > Platform Settings > SDKs, click the "+" button to add a new SDK.
In the pop-up, go into your Android SDK folder and click "Choose"
Another pop-up will appear asking for which SDK and JDK you want to use. Choose any Android SDK and the 1.7 JDK.
Go to Project Structure > Project Settings > Project and change your Project SDK to the one you just created. You should see the name of the SDK contain the new Java version that you installed.
C:\Program Files\Android\Android Studio\jre\bin>java -version
openjdk version "1.8.0_76-release"
OpenJDK Runtime Environment (build 1.8.0_76-release-b03)
OpenJDK 64-Bit Server VM (build 25.76-b03, mixed mode)
Somehow the Studio installer would install another version under:
C:\Program Files\Android\Android Studio\jre\jre\bin>java -version
openjdk version "1.8.0_76-release"
OpenJDK Runtime Environment (build 1.8.0_76-release-b03)
OpenJDK 64-Bit Server VM (build 25.76-b03, mixed mode)
where the latest version was installed the Java DevKit installer in:
C:\Program Files\Java\jre1.8.0_121\bin>java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
Need to clean up the Android Studio so it would use the proper latest 1.8.0 versions.
According to How to set Java SDK path in AndroidStudio?
one could override with a specific JDK but when I renamed
C:\Program Files\Android\Android Studio\jre\jre\
to:
C:\Program Files\Android\Android Studio\jre\oldjre\
And restarted Android Studio, it would complain that the jre was invalid.
When I tried to aecify an JDK to pick the one in C:\Program Files\Java\jre1.8.0_121\bin
or:
C:\Program Files\Java\jre1.8.0_121\
It said that these folders are invalid. So I guess that the embedded version must have some special purpose.
This problem arises due to incompatible JDK version.
Download and install latest JDK(currently its 8) from java official site in case you are using previous versions. Then in Android Studio go to File->Project Structure->SDK location -> JDK location and set it to 'C:\Program Files\Java\jdk1.8.0_121' (Default location of JDK). Gradle sync your project and you are all set...
And now this is located in Gradle settings:
1) File >>> Project Structure OR press Ctrl+Alt+Shift+S
2) In SDK Location Tab you will find SDK Location:
3) Change your Project SDK location to the one you have installed
4) Sync your project
If you are using new android studio 2021+ then you can find or update JDK settings by navigating to
File > Settings... > Build, Execution, Deployment > Build Tools >
Gradle
on windows
Android Studio > Preferences... > Build, Execution, Deployment > Build
Tools > Gradle
on Mac
Go to File>Project Structure>JDK location:
Here, you have to set the directory path exactly same, in which you have installed the java version.
Also, you have to mention the paths of SDK for project run on emulator successfully.
Why This Problem Occurs: It is due to the unsynchronized java version directory that should be available to Android Studio for java code compilance.
Click "use embedded JDK" on version Android Studio 3.2.1

Resources