android - React Native 0.60 - 无法使用 react-native run-android 运行应用程序:java.lang.NoClassDefFoundError
问题描述
在长周末之前的星期五很晚,我在运行react-native
应用程序时遇到了问题。当前版本是0.60
(最新),并运行命令
react-native run-android
导致debug
构建成功安装在我连接的应用程序上,但在打开时崩溃并出现以下错误:
致命异常:主
进程:com.myApp,PID:XXXX
java.lang.NoClassDefFoundError:解析失败: Lcom
/google/android/gms/common/internal/zzbq
谷歌搜索这个神秘的错误会导致一些结果表明MultiDex
是罪魁祸首,以及如何处理这个问题。为了研究,我将链接一些线程:
Android 3.1.1 - 解析失败:Lcom/google/android/gms/common/internal/zzbq;
在路径上找不到类“com.google.android.gms.common.internal.zzbq”:DexPathList
(链接到以前的结果)
解决方案之一,即覆盖if name contains to versionuse version
适用于builds:com.google.android.gms
multidex
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
构建完全不同的问题:
找不到 com.google.android.gms:play-services-vision-image-label:12.0.1。
找不到 com.google.android.gms:play-services-clearcut:12.0.1
找不到 com.google.android.gms:play-services-phenotype:12.0.1
找不到 com.google.android.gms :play-services-stats:12.0.1
所有这些都说“XXX:17.0.1 需要”,所以我尝试details.useVersion "17.0.1"
了,但这导致了类似的问题:
找不到 com.google.android.gms:play-services-location:17.0.1
找不到 com.google.android.gms:play-services-base:17.0.1
找不到 com.google.android.gms :play-services-basement:17.0.1
找不到 com.google.android.gms:play-services-tasks:17.0.1
其中一些模块具有 version 17.0.1
,而其他模块位于17.0.2
or 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'
}
This results in the same error for both debug
and release
builds, and a little bit of extra Googling uncovers that MultiDex
is not required for SDK version > 27.0.0
(looks to be using 28.0.0
/ 28.0.3
)
I've been banging my head against this for the entire day and haven't been able to make any progress. Has anyone seen this issue as it pertains to React Native 0.60?
Note: There are a couple plugins that are using these com.google.android.gms
in my project, namely:
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')}"
解决方案
Solution is to use the new bundle/build process for Android .aab
and .apk
files, as shown on React Native documentation. Current process that is throwing errors is as follows:
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`)
When successful, this generates the .apk
file and installs it on device, similar to downloading/installing directly from the Play Store. Various bugs in build process are preventing this, as detailed above.
React Native documentation suggest to use a different set of commands to generate .aab
file, and from that the .apk
:
cd android
./gradlew clean
./gradlew bundleRelease
cd .. && react-native run-android --variant=release
Complete details can be found at https://facebook.github.io/react-native/docs/signed-apk-android#generating-the-release-apk. Information about generating Signed APK included since previous implementation.
Using this approach, .aab
and .apk
files are generated and installed on device, but another issue arises in lack of ic_launcher_rounded
. See React Native 0.60 - ic_launcher_round missing for Release Bundle/Build for details. Marking question as closed when allowed.
推荐阅读
- php - Laravel 刀片路线在标题上显示方法
- asynchronous - NServiceBus 的自定义日志实现与 AsyncLocal 抛出异常
- javascript - php中的Morris.js条形图?
- amazon-web-services - 是否有用于轮换 AWS RDS 证书的文档?
- matplotlib - matplotlib:如何从直方图条中获取颜色(或 facecolor)?
- c# - 提供具有复杂设置配置的 Azure Web 应用
- ansible - no_device:是的,在使用 Ansible 创建 ami 时不起作用
- ruby-on-rails - 自动化生产页面创建
- c++ - QObject::connect: 需要括号,信号 QSerialPort::readyRead in ..\voltage_sensor\dialop.cpp:41
- python - Tkinter 和 Socket 之间的链接