React Native 0.60 - 无法 运行 具有 react-native 运行-android 的应用程序:java.lang.NoClassDefFoundError
React Native 0.60 - Unable to Run App with react-native run-android: java.lang.NoClassDefFoundError
在长周末之前的周五很晚,我遇到了 运行 react-native
应用程序的问题。当前版本是 0.60
(最新),并且 运行 命令
react-native run-android
导致 debug
构建成功安装在我连接的应用程序上,但在打开时崩溃并出现以下错误:
FATAL EXCEPTION: main
Process: com.myApp, PID: XXXX
java.lang.NoClassDefFoundError: Failed resolution of:
Lcom/google/android/gms/common/internal/zzbq
谷歌搜索这个神秘错误会得到许多结果,表明 MultiDex
是罪魁祸首,以及如何处理这个问题。为了研究的缘故,我将 link 一些线程:
Didn't find class "com.google.android.gms.common.internal.zzbq" on path: DexPathList
(links 到上一个结果)
其中一个解决方案,即如果名称包含 multidex
则为 com.google.android.gms
覆盖 use version
到版本 12.0.1
适用于 debug
建造:
在android/build.gradle
中:
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.google.android.gms'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "12.0.1"
}
}
}
}
但是,这会导致 production
构建完全不同的问题:
Could not find com.google.android.gms:play-services-vision-image-label:12.0.1.
Could not find com.google.android.gms:play-services-clearcut:12.0.1
Could not find com.google.android.gms:play-services-phenotype:12.0.1
Could not find com.google.android.gms:play-services-stats:12.0.1
所有这些都在说 "Required by XXX:17.0.1",所以我尝试了 details.useVersion "17.0.1"
,但这导致了类似的问题:
Could not find com.google.android.gms:play-services-location:17.0.1
Could not find com.google.android.gms:play-services-base:17.0.1
Could not find com.google.android.gms:play-services-basement:17.0.1
Could not find com.google.android.gms:play-services-tasks:17.0.1
其中一些模块的版本为 17.0.1
,而其他模块的版本为 17.0.2
或 17.0.0
,因此严格的 use version X.Y.Z
不适用于 release
构建。
如果我删除此 subProjects { ... }
声明并尝试按照其他答案中的建议启用 MultiDex
:
在android/app/build.gradle
中:
android {
defaultConfig {
...
multiDexEnabled true
}
}
dependencies {
...
implementation 'com.android.support:multidex:1.0.3'
}
这会导致 debug
和 release
构建出现相同的错误,一些额外的谷歌搜索会发现 SDK 版本 > [=40] 不需要 MultiDex
=](看起来正在使用 28.0.0
/ 28.0.3
)
我整天都在为此苦苦思索,一直没有取得任何进展。有没有人看到这个问题因为它属于 React Native 0.60?
注意:在我的项目中有几个插件正在使用这些 com.google.android.gms
,即:
react-native-background-geolocation
implementation "com.google.android.gms:play-services-location:$playServicesLocationVersion"
react-native-camera
generalImplementation "com.google.android.gms:play-services-vision:$googlePlayServicesVisionVersion"
react-native-device-info
implementation "com.google.android.gms:play-services-gcm:${safeExtGet('googlePlayServicesVersion', '16.1.0')}"
解决方案是对 Android .aab
和 .apk
文件使用新的 bundle/build 进程,如 React Native 文档所示。当前抛出错误的进程如下:
cd android
./gradlew clean
cd ..
bundleAPK (`react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/`)
buildReleaseAPK (`cd ./android && ./gradlew assembleRelease && cd ..`
installReleaseAPKAlt (`adb install -r ./android/app/build/outputs/apk/release/app-release.apk`)
成功后,将生成 .apk
文件并将其安装到设备上,类似于直接从 Play 商店 downloading/installing。如上所述,构建过程中的各种错误阻止了这一点。
React Native 文档建议使用一组不同的命令来生成 .aab
文件,并从中生成 .apk
:
cd android
./gradlew clean
./gradlew bundleRelease
cd .. && react-native run-android --variant=release
可在 https://facebook.github.io/react-native/docs/signed-apk-android#generating-the-release-apk 找到完整的详细信息。自上次实施以来包含有关生成签名 APK 的信息。
使用这种方法,生成了 .aab
和 .apk
文件并安装在设备上,但是缺少 ic_launcher_rounded
会出现另一个问题。有关详细信息,请参阅 。允许时将问题标记为关闭。
在长周末之前的周五很晚,我遇到了 运行 react-native
应用程序的问题。当前版本是 0.60
(最新),并且 运行 命令
react-native run-android
导致 debug
构建成功安装在我连接的应用程序上,但在打开时崩溃并出现以下错误:
FATAL EXCEPTION: main
Process: com.myApp, PID: XXXX
java.lang.NoClassDefFoundError: Failed resolution of:
Lcom/google/android/gms/common/internal/zzbq
谷歌搜索这个神秘错误会得到许多结果,表明 MultiDex
是罪魁祸首,以及如何处理这个问题。为了研究的缘故,我将 link 一些线程:
Didn't find class "com.google.android.gms.common.internal.zzbq" on path: DexPathList
(links 到上一个结果)
其中一个解决方案,即如果名称包含 multidex
则为 com.google.android.gms
覆盖 use version
到版本 12.0.1
适用于 debug
建造:
在android/build.gradle
中:
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.google.android.gms'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "12.0.1"
}
}
}
}
但是,这会导致 production
构建完全不同的问题:
Could not find com.google.android.gms:play-services-vision-image-label:12.0.1.
Could not find com.google.android.gms:play-services-clearcut:12.0.1
Could not find com.google.android.gms:play-services-phenotype:12.0.1
Could not find com.google.android.gms:play-services-stats:12.0.1
所有这些都在说 "Required by XXX:17.0.1",所以我尝试了 details.useVersion "17.0.1"
,但这导致了类似的问题:
Could not find com.google.android.gms:play-services-location:17.0.1
Could not find com.google.android.gms:play-services-base:17.0.1
Could not find com.google.android.gms:play-services-basement:17.0.1
Could not find com.google.android.gms:play-services-tasks:17.0.1
其中一些模块的版本为 17.0.1
,而其他模块的版本为 17.0.2
或 17.0.0
,因此严格的 use version X.Y.Z
不适用于 release
构建。
如果我删除此 subProjects { ... }
声明并尝试按照其他答案中的建议启用 MultiDex
:
在android/app/build.gradle
中:
android {
defaultConfig {
...
multiDexEnabled true
}
}
dependencies {
...
implementation 'com.android.support:multidex:1.0.3'
}
这会导致 debug
和 release
构建出现相同的错误,一些额外的谷歌搜索会发现 SDK 版本 > [=40] 不需要 MultiDex
=](看起来正在使用 28.0.0
/ 28.0.3
)
我整天都在为此苦苦思索,一直没有取得任何进展。有没有人看到这个问题因为它属于 React Native 0.60?
注意:在我的项目中有几个插件正在使用这些 com.google.android.gms
,即:
react-native-background-geolocation
implementation "com.google.android.gms:play-services-location:$playServicesLocationVersion"
react-native-camera
generalImplementation "com.google.android.gms:play-services-vision:$googlePlayServicesVisionVersion"
react-native-device-info
implementation "com.google.android.gms:play-services-gcm:${safeExtGet('googlePlayServicesVersion', '16.1.0')}"
解决方案是对 Android .aab
和 .apk
文件使用新的 bundle/build 进程,如 React Native 文档所示。当前抛出错误的进程如下:
cd android
./gradlew clean
cd ..
bundleAPK (`react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/`)
buildReleaseAPK (`cd ./android && ./gradlew assembleRelease && cd ..`
installReleaseAPKAlt (`adb install -r ./android/app/build/outputs/apk/release/app-release.apk`)
成功后,将生成 .apk
文件并将其安装到设备上,类似于直接从 Play 商店 downloading/installing。如上所述,构建过程中的各种错误阻止了这一点。
React Native 文档建议使用一组不同的命令来生成 .aab
文件,并从中生成 .apk
:
cd android
./gradlew clean
./gradlew bundleRelease
cd .. && react-native run-android --variant=release
可在 https://facebook.github.io/react-native/docs/signed-apk-android#generating-the-release-apk 找到完整的详细信息。自上次实施以来包含有关生成签名 APK 的信息。
使用这种方法,生成了 .aab
和 .apk
文件并安装在设备上,但是缺少 ic_launcher_rounded
会出现另一个问题。有关详细信息,请参阅