react-native icon indicating copy to clipboard operation
react-native copied to clipboard

I can't install android app

Open Choi-Juno opened this issue 3 years ago • 6 comments

Description

There is a bug that does not install the app when I build android after the project is first created.

yarn run v1.22.17 $ react-native run-android info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag. Jetifier found 863 file(s) to forward-jetify. Using 10 workers... info JS server already running. info Installing the app...

Task :app:processDebugMainManifest FAILED 11 actionable tasks: 2 executed, 9 up-to-date

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:processDebugMainManifest'.

Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @3ddaca54

  • 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 2s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:processDebugMainManifest'.

Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @3ddaca54

  • 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 2s

at makeError (/Users/junochoi/Documents/ReactNative/TodoApp/node_modules/execa/index.js:174:9)
at /Users/junochoi/Documents/ReactNative/TodoApp/node_modules/execa/index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (/Users/junochoi/Documents/ReactNative/TodoApp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
at async Command.handleAction (/Users/junochoi/Documents/ReactNative/TodoApp/node_modules/@react-native-community/cli/build/index.js:192:9)

info Run CLI with --verbose flag for more details. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Version

0.67.2

Output of npx react-native info

System: OS: macOS 12.2 CPU: (10) arm64 Apple M1 Pro Memory: 97.39 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node Yarn: 1.22.17 - ~/.nvm/versions/node/v16.14.0/bin/yarn npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm Watchman: 2022.02.14.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.2 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3 Android SDK: API Levels: 29, 30, 31, 32 Build Tools: 29.0.2, 30.0.2, 30.0.3, 31.0.0 System Images: android-29 | Intel x86 Atom, android-29 | Intel x86 Atom_64, android-29 | Google APIs ARM 64 v8a, android-29 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom_64, android-29 | Google Play ARM 64 v8a, android-29 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom_64, android-30 | Intel x86 Atom_64, android-30 | Google APIs Intel x86 Atom, android-30 | Google APIs Intel x86 Atom_64, android-30 | Google Play ARM 64 v8a, android-31 | Intel x86 Atom_64, android-31 | Google APIs ARM 64 v8a, android-31 | Google APIs Intel x86 Atom_64, android-32 | Google Play ARM 64 v8a Android NDK: Not Found IDEs: Android Studio: 2021.1 AI-211.7628.21.2111.8139111 Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild Languages: Java: 17.0.2 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.67.2 => 0.67.2 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

In my case, it does not work immediately after project creation.

Snack, code example, screenshot, or link to a repository

No response

Choi-Juno avatar Feb 19 '22 12:02 Choi-Juno

Try using the lowest version of Java and then work your way up to the highest compatible version. If I remember right this is a JAVA16+ problem.

Either by point JAVA_HOME to a compatible 8.0 or 11 version or setup the config to build.gradle (android/app) and maybe also the root project build.gradle ,note that there are two such build.gradle files one in the android root folder and the other in the project app if you cant actually rollback your java (not recommended) this is probably the safer option.

 allprojects {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
}.

depending on your gradle version you may have to write it in as compile options instead

compileOptions {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

joe-sam avatar Feb 19 '22 18:02 joe-sam

Changing the gradle version worked for me. To change it go to AwesomeProject/android/build.gradle

  1. You should find a line in dependencies that goes as follows: classpath("com.android.tools.build:gradle:4.2.2")

  2. Change it to: classpath("com.android.tools.build:gradle:7.1.1")

  3. Next, clean out your AwesomeProject/android/.gradle by running this in the terminal (assuming you are in the AwesomeProject directory): cd android && ./gradlew clean && cd ..

  4. Next, if you already have metro running shut it down and run it again: npx react-native start

Now running npx react-native run-android should work. If not make sure the emulator has:

  • internet access
  • USB debugging is switched on

For reference, my java version is 11.0.13.

Note to the react team:

  • Please ensure that you mention this java vs gradle version mismatch issue in the getting started pages. It should mention the maximum java version for the 4.2.2 gradle version or you should update the gradle version used in the lastest react native version. This issue wasted a week of my life lol.

xtosis avatar Feb 22 '22 10:02 xtosis

  • It should mention the maximum java version for the 4.2.2 gradle version or you should update the gradle version used in the lastest react native version.

There is a note about it in the Getting Started page: https://reactnative.dev/docs/environment-setup#installing-dependencies

If you have already installed JDK on your system, make sure it is JDK 11 or newer.

cortinico avatar Feb 25 '22 13:02 cortinico

But it doesn't mention what gradle version should be used for that particular JDK version and this is a problem as I had to manually change the default gradle version from 4.2.2 to 7.1.1 for it to work with JDK 11. You guys should either update react native to use version 7.1.1 by default or mention in your getting started pages that a lower JDK version should be used as gradle 4.2.2 doesn't support JDK 11.

xtosis avatar Feb 25 '22 14:02 xtosis

a lower JDK version should be used as gradle 4.2.2 doesn't support JDK 11.

That's not correct.

Android Gradle Plugin (not gradle) version 4.2.2 supports JDK >= 8 Android Gradle Plugin (not gradle) version 7.0.x supports JDK >= 11

You guys should either update react native to use version 7.1.1 by default or mention in your getting started pages that a lower

The default template is already updated to use AGP 7.0.x

cortinico avatar Feb 25 '22 14:02 cortinico

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Aug 25 '22 02:08 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Sep 03 '22 02:09 github-actions[bot]