React NativeでAndroidアプリのビルド失敗対処法まとめ

React Nativeとはいえ、モジュールを使うとネイティブのコードが沢山追加されます。
だから何もしなくても勝手にクロスプラットフォーム対応!とは世の中そう上手くいきません。世知辛ぇよ。
だから先にiOSアプリをひと通り実装してから、いざAndroidアプリをビルドしてみると・・出るわ出るわエラーが笑

筆者がまさにそういうやり方でアプリ作っているので、Androidビルドで生まれた魑魅魍魎たちの退治記録を以下にまとめました。ご参照下さい。

Android SDK Build Tools revision 23.0.1 が必要と怒られる

RNのバージョンによって要求されるSDKも異なるかもしれません。
こんな風に怒られます:

> react-native run-android
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> failed to find Build Tools revision 23.0.1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 3.994 secs
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/android-setup.html

という訳でインストールしてあげます。
以下でインストールできるsdkの一覧を取得する。

> android list sdk -a

リスト左の番号を-tオプションに指定してインストール:

> android update sdk -a -u -t 12

androidコマンドなんて無ぇよと言われる

SDKのバージョンが新しいと、androidコマンドを実行すると以下のように怒られます:

The android command is no longer available.
For manual SDK and AVD management, please use Android Studio.
For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager

おとなしくAndroid Studioからインストールしてください。

Could not find com.android.support:design:25.0.1

気を取り直して再ビルド!
次は以下のように文句を言われます:

JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)<home>
downloadRobolectricDependencies /Users/<home>/react-native-app/android/build/robolectric-dependencies
Download https://jcenter.bintray.com/com/aurelhubert/ahbottomnavigation/1.3.3/ahbottomnavigation-1.3.3.pom
Download https://jcenter.bintray.com/com/balysv/materialmenu/material-menu-toolbar/1.5.4/material-menu-toolbar-1.5.4.pom
Download https://jcenter.bintray.com/com/balysv/materialmenu/material-menu/1.5.4/material-menu-1.5.4.pom

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> A problem occurred configuring project ':react-native-navigation'.
   > Could not resolve all dependencies for configuration ':react-native-navigation:_debugCompile'.
      > Could not find com.android.support:design:25.0.1.
        Searched in the following locations:
            file:/Users/<home>/.m2/repository/com/android/support/design/25.0.1/design-25.0.1.pom
            file:/Users/<home>/.m2/repository/com/android/support/design/25.0.1/design-25.0.1.jar
            https://jcenter.bintray.com/com/android/support/design/25.0.1/design-25.0.1.pom
            https://jcenter.bintray.com/com/android/support/design/25.0.1/design-25.0.1.jar
            file:/Users/<home>/react-native-app/node_modules/react-native/android/com/android/support/design/25.
0.1/design-25.0.1.pom
            file:/Users/<home>/react-native-app/node_modules/react-native/android/com/android/support/design/25.
0.1/design-25.0.1.jar
            file:/Users/<home>/Library/Android/sdk/extras/android/m2repository/com/android/support/design/25.0.1/design-25.0.1.pom
            file:/Users/<home>/Library/Android/sdk/extras/android/m2repository/com/android/support/design/25.0.1/design-25.0.1.jar
            file:/Users/<home>/Library/Android/sdk/extras/google/m2repository/com/android/support/design/25.0.1/design-25.0.1.pom
            file:/Users/<home>/Library/Android/sdk/extras/google/m2repository/com/android/support/design/25.0.1/design-25.0.1.jar
        Required by:
            inkdrop:react-native-navigation:unspecified
      > Could not find com.android.support:appcompat-v7:25.0.1.
        Searched in the following locations:
            file:/Users/<home>/.m2/repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.pom
            file:/Users/<home>/.m2/repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.jar
            https://jcenter.bintray.com/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.pom
            https://jcenter.bintray.com/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.jar
            file:/Users/<home>/react-native-app/node_modules/react-native/android/com/android/support/appcompat-
v7/25.0.1/appcompat-v7-25.0.1.pom
            file:/Users/<home>/react-native-app/node_modules/react-native/android/com/android/support/appcompat-
v7/25.0.1/appcompat-v7-25.0.1.jar
            file:/Users/<home>/Library/Android/sdk/extras/android/m2repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.pom
            file:/Users/<home>/Library/Android/sdk/extras/android/m2repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.jar
            file:/Users/<home>/Library/Android/sdk/extras/google/m2repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.pom
            file:/Users/<home>/Library/Android/sdk/extras/google/m2repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.jar
        Required by:
            inkdrop:react-native-navigation:unspecified
      > Could not find com.android.support:appcompat-v7:25.0.1.
        Searched in the following locations:
            file:/Users/<home>/.m2/repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.pom
            file:/Users/<home>/.m2/repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.jar
            https://jcenter.bintray.com/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.pom
            https://jcenter.bintray.com/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.jar
            file:/Users/<home>/react-native-app/node_modules/react-native/android/com/android/support/appcompat-
v7/25.0.1/appcompat-v7-25.0.1.pom
            file:/Users/<home>/react-native-app/node_modules/react-native/android/com/android/support/appcompat-
v7/25.0.1/appcompat-v7-25.0.1.jar
            file:/Users/<home>/Library/Android/sdk/extras/android/m2repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.pom
            file:/Users/<home>/Library/Android/sdk/extras/android/m2repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.jar
            file:/Users/<home>/Library/Android/sdk/extras/google/m2repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.pom
            file:/Users/<home>/Library/Android/sdk/extras/google/m2repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.jar
        Required by:
            inkdrop:react-native-navigation:unspecified > com.facebook.react:react-native:0.39.2
      > Could not find com.android.support:design:25.0.1.
        Searched in the following locations:
            file:/Users/<home>/.m2/repository/com/android/support/design/25.0.1/design-25.0.1.pom
            file:/Users/<home>/.m2/repository/com/android/support/design/25.0.1/design-25.0.1.jar
            https://jcenter.bintray.com/com/android/support/design/25.0.1/design-25.0.1.pom
            https://jcenter.bintray.com/com/android/support/design/25.0.1/design-25.0.1.jar
            file:/Users/<home>/react-native-app/node_modules/react-native/android/com/android/support/design/25.
0.1/design-25.0.1.pom
            file:/Users/<home>/react-native-app/node_modules/react-native/android/com/android/support/design/25.
0.1/design-25.0.1.jar
            file:/Users/<home>/Library/Android/sdk/extras/android/m2repository/com/android/support/design/25.0.1/design-25.0.1.pom
            file:/Users/<home>/Library/Android/sdk/extras/android/m2repository/com/android/support/design/25.0.1/design-25.0.1.jar
            file:/Users/<home>/Library/Android/sdk/extras/google/m2repository/com/android/support/design/25.0.1/design-25.0.1.pom
            file:/Users/<home>/Library/Android/sdk/extras/google/m2repository/com/android/support/design/25.0.1/design-25.0.1.jar
        Required by:
            inkdrop:react-native-navigation:unspecified > com.aurelhubert:ahbottomnavigation:1.3.3
      > Could not find com.android.support:appcompat-v7:25.0.1.
        Searched in the following locations:
            file:/Users/<home>/.m2/repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.pom
            file:/Users/<home>/.m2/repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.jar
            https://jcenter.bintray.com/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.pom
            https://jcenter.bintray.com/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.jar
            file:/Users/<home>/react-native-app/node_modules/react-native/android/com/android/support/appcompat-
v7/25.0.1/appcompat-v7-25.0.1.pom
            file:/Users/<home>/react-native-app/node_modules/react-native/android/com/android/support/appcompat-
v7/25.0.1/appcompat-v7-25.0.1.jar
            file:/Users/<home>/Library/Android/sdk/extras/android/m2repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.pom
            file:/Users/<home>/Library/Android/sdk/extras/android/m2repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.jar
            file:/Users/<home>/Library/Android/sdk/extras/google/m2repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.pom
            file:/Users/<home>/Library/Android/sdk/extras/google/m2repository/com/android/support/appcompat-v7/25.0.1/appcompat-v7-25.0.1.jar
        Required by:
            inkdrop:react-native-navigation:unspecified > com.balysv.materialmenu:material-menu-toolbar:1.5.4

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 13.908 secs
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/android-setup.html

なげーんだよ!
要するに以下のライブラリが無い、と。

Could not find com.android.support:design:25.0.1.
Could not find com.android.support:appcompat-v7:25.0.1.

これはAndroid StudioでAndroid SDKを最新に更新してあげれば解決しました。
実際には以下のディレクトリにインストールされます。

ls -l ~/Library/Android/sdk/extras/android/m2repository/com/android/support/appcompat-v7/25.0.1/
total 2936
-rw-r--r--  1 nora  staff      261 Mar 15 10:18 appcompat-v7-25.0.1-javadoc.jar
-rw-r--r--  1 nora  staff       32 Mar 15 10:18 appcompat-v7-25.0.1-javadoc.jar.md5
-rw-r--r--  1 nora  staff       40 Mar 15 10:18 appcompat-v7-25.0.1-javadoc.jar.sha1
-rw-r--r--  1 nora  staff   445548 Mar 15 10:18 appcompat-v7-25.0.1-sources.jar
-rw-r--r--  1 nora  staff       32 Mar 15 10:18 appcompat-v7-25.0.1-sources.jar.md5
-rw-r--r--  1 nora  staff       40 Mar 15 10:18 appcompat-v7-25.0.1-sources.jar.sha1
-rw-r--r--  1 nora  staff  1012220 Mar 15 10:18 appcompat-v7-25.0.1.aar
-rw-r--r--  1 nora  staff       32 Mar 15 10:18 appcompat-v7-25.0.1.aar.md5
-rw-r--r--  1 nora  staff       40 Mar 15 10:18 appcompat-v7-25.0.1.aar.sha1
-rw-r--r--  1 nora  staff     1114 Mar 15 10:18 appcompat-v7-25.0.1.pom
-rw-r--r--  1 nora  staff       32 Mar 15 10:18 appcompat-v7-25.0.1.pom.md5
-rw-r--r--  1 nora  staff       40 Mar 15 10:18 appcompat-v7-25.0.1.pom.sha1

Cannot evaluate module react-native-webview-bridge : Configuration with name 'default' not found

エラー:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Cannot evaluate module react-native-webview-bridge : Configuration with name 'default' not found.

react-native-webview-bridgeは使っていないモジュール。リンクしたままだったので怒られた。
android/app/build.gradleから該当のcompileステートメントを削除。
自分の場合は以下のような感じ:

diff --git a/android/app/build.gradle b/android/app/build.gradle
index 058d7a8..ce25205 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -132,7 +132,6 @@ dependencies {
     compile project(':react-native-mixpanel')
     compile project(':react-native-keychain')
     compile project(':react-native-navigation')
-    compile project(':react-native-webview-bridge')
     compile project(':react-native-vector-icons')
     compile fileTree(dir: "libs", include: ["*.jar"])
     compile "com.android.support:appcompat-v7:23.0.1"

Android Emulatorが立ち上がらねぇ

バーチャルマシン一覧は以下のように取得:

> cd $ANDROID_HOME/tools
> emulator -list-avds
Android_ARMv7a
Android_Accelerated_x86
Nexus_5_API_25

いざ起動:

> emulator -avd Nexus_5_API_25

失敗しました。あああん?

> emulator -avd Pixel_API_25
emulator: WARNING: encryption is off
Hax is enabled
Hax ram_size 0x60000000
HAX is working and emulator runs in fast virt mode.
Failed to sync vcpu reg
Failed to sync vcpu reg
Failed to sync vcpu reg
Failed to sync HAX vcpu contextInternal error: Initial hax sync failed

DockerやVirtualBoxと併用できない

なんかそういう仕様らしいです。不便だ!
しょうがないのでDockerを終了する:

> launchctl list | grep 'VirtualBox|docker'
-       0       com.docker.helper
1241    0       com.docker.docker.37028

> launchctl stop com.docker.docker.37028

> docker ps -a
Error response from daemon: Bad response from Docker engine

> emulator -avd Pixel_API_25
emulator: WARNING: encryption is off
Hax is enabled
Hax ram_size 0x60000000
HAX is working and emulator runs in fast virt mode.

Got it working!!!!!!!! haha!!!

エラーの果てに得たもの

それは祝福の起動画面。

投稿者:

Takuya

Digital crafts(man|dog). Love photography. Always making otherwise sleeping. born in 1984.

コメントを残す

以下に詳細を記入するか、アイコンをクリックしてログインしてください。

WordPress.com ロゴ

WordPress.com アカウントを使ってコメントしています。 ログアウト / 変更 )

Twitter 画像

Twitter アカウントを使ってコメントしています。 ログアウト / 変更 )

Facebook の写真

Facebook アカウントを使ってコメントしています。 ログアウト / 変更 )

Google+ フォト

Google+ アカウントを使ってコメントしています。 ログアウト / 変更 )

%s と連携中