Can't run app on Android Device :
Building and installing the app on the device (cd android && ./gradlew installDebug)...
FAILURE: Build failed with an exception.
What went wrong:
Could not determine java version from '11.0.1'.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Get more help at https://help.gradle.org
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
__TL; DR__ Downgrade your Java version to Java 8
Sometime between Java 9 and Java 11, the format of java -version has changed, resulting in breakage in Gradle. Gradle has fixed the issue in Gradle 4.7, but React-native's template hasn't upgraded its Gradle version yet.
However, as upgrading Gradle may cause unwanted effects, I think you should workaround this by downgrading your Java version to Java 8. Meanwhile, maintainers can take a look if Gradle (& Android's build-tools) can be upgraded and if any steps are required first.
Can you run react-native info and edit your issue to include these results under the Environment section?
If you believe this information is irrelevant to the reported issue, you may write [skip envinfo] under Environment to let us know.
OK I've downgrade the java version to 8: @peat-psuwit
getting this Error (even thought that I have local.properties in my root dir.
Error log:
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring project ':app'.
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 1s
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
If you followed the instruction in React-native's site, I recommend you to remove local.properties. Then it should use the value from the environment variable.
However, if you still can't build your app after that, I would recommend you to ask the question elsewhere and keep this issue about Java 11 support. https://hackr.io/forum/react-native seems to be a good place to start.
Thank you Mr. @peat-psuwit .
Solved
1- Delete Java 11 , 2-install Java 8 , 3-Create new file (local.properties) and set the SDK path in it .
Was this updated in React Native now so one can use 11?
@Abdohurbly in which directory did you create the local.properties and what did you write to set the SDK path?
Is there anyway to run android without uninstalling java 11? I have tried changing gradle versions to: 5.0 but no luck.
Yes - just use the ol' update-alternatives trick to select which version you want to use, or update the local environment variable $JAVA_HOME to the correct place.
E.g.:
# update-alternatives --list java
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
# update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
# java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-0ubuntu0.18.10.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
# update-alternatives --set java /usr/lib/jvm/java-11-openjdk-amd64/bin/java
# java -version
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment (build 11.0.1+13-Ubuntu-3ubuntu118.10ppa1)
OpenJDK 64-Bit Server VM (build 11.0.1+13-Ubuntu-3ubuntu118.10ppa1, mixed mode, sharing)
You can use new Java with this:
buildscript.dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
in global build.gradle
also change the gradle url to:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
in gradle/wrapper/gradle-wrapper.properties
run the build once with old java and these changes, all subsequent builds succeed with new java.
@peat-psuwit it's fine. everything works like it should.
# update-alternatives --list java
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
# update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
# java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-0ubuntu0.18.10.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
This helped me. Please note that # means superuser access so you may have to use sudo otherwise.
Most helpful comment
Yes - just use the ol'
update-alternativestrick to select which version you want to use, or update the local environment variable $JAVA_HOME to the correct place.E.g.: