4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

React NativeでAndroidで起動するまでに起きたエラー

Last updated at Posted at 2021-03-12

前提

Setting up the development environmentでこのコマンドを実行した直後。

$ npx react-native init AwesomeProject

続くエラーに対応した。

  1. JDKのversionが古い
  2. build時に gradle のエラー
  3. NDKのバージョンが適合しない

1. JDKのversionが古い

$ npx @react-native-community/cli doctor
Common
 ✓ Node.js
 ✓ yarn
 ✓ Watchman - Used for watching changes in the filesystem when in development mode

Android
 ✖ JDK
   - Version found: 1.8.0_281
   - Version supported: >= 8
 ✓ Android Studio - Required for building and installing your app on Android
 ✓ Android SDK - Required for building and installing your app on Android
 ✓ ANDROID_HOME

iOS
 ✓ Xcode - Required for building and installing your app on iOS
 ✓ CocoaPods - Required for installing iOS dependencies
 ✓ ios-deploy - Required for installing your app on a physical device with the CLI

Errors:   1
Warnings: 0
$ java -version
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)

make sure it is JDK 8 or newer

紛らわしいが、バージョン x なら 1.x.0 のように表記される。
8以上だから8でOKだと思ったが、NGの場合もあるらしい。

対応

JDKをアップデート
cf. HomeBrew で AdoptOpenJDK をインストールしてみた(訂正版) - Qiita

$ brew tap AdoptOpenJDK/openjdk
$ brew cask install adoptopenjdk
$ java -version
openjdk version "15.0.2" 2021-01-19
OpenJDK Runtime Environment AdoptOpenJDK (build 15.0.2+7)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 15.0.2+7, mixed mode, sharing)
$ npx @react-native-community/cli doctor
Common
 ✓ Node.js
 ✓ yarn
 ✓ Watchman - Used for watching changes in the filesystem when in development mode

Android
 ✓ JDK
 ✓ Android Studio - Required for building and installing your app on Android
 ✓ Android SDK - Required for building and installing your app on Android
 ✓ ANDROID_HOME

iOS
 ✓ Xcode - Required for building and installing your app on iOS
 ✓ CocoaPods - Required for installing iOS dependencies
 ✓ ios-deploy - Required for installing your app on a physical device with the CLI

Errors:   0
Warnings: 0

2. build時に gradle のエラー

$ npx react-native run-android

...

* What went wrong:
Could not initialize class org.codehaus.groovy.reflection.ReflectionCache

...

対応

Gradleをバージョンアップ: gradle-6.5-all.zip に設定した
cf. JDK 14 support · Issue #10248 · gradle/gradle
cf. 開発メモ その198 Could not initialize class org.codehaus.groovy.reflection.ReflectionCache · A certain engineer "COMPLEX"

3. NDKのバージョンが適合しない

$ npx react-native run-android

...

> Task :app:compileDebugJavaWithJavac

> Task :app:stripDebugDebugSymbols FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings
23 actionable tasks: 23 executed
Note: /Users/shuheikatori/dev/AwesomeProject/android/app/src/debug/java/com/awesomeproject/ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:stripDebugDebugSymbols'.
> No toolchains found in the NDK toolchains folder for ABI with prefix: arm-linux-androideabi

...

対応

NDKのバージョンを 20.1.xxxxx に変更
よくわからないバージョンの不適合とかキツい。
cf. [tool] No toolchains found in the NDK toolchains folder for ABI with prefix: arm-linux-androideabi · Issue #76393 · flutter/flutter

🎉

$ npx react-native run-android

...

BUILD SUCCESSFUL in 12s
27 actionable tasks: 5 executed, 22 up-to-date
info Connecting to the development server...
info Starting the app on "emulator-5554"...
Starting: Intent { cmp=com.awesomeproject/.MainActivity }
4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?