问题描述
在一个漫长的周末之前的周五晚,我在运行react-native
应用程序时遇到了问题.当前版本为0.60
(最新),并运行命令
It's late on Friday before a long weekend, and I'm having issues running an react-native
app. Current version is 0.60
(latest), and running the command
react-native run-android
生成一个 debug
构建,该构建成功安装在我连接的应用程序上,但在打开时崩溃,并显示以下错误:
Results in a debug
build that successfully installs on my connected app, but crashes upon opening with the following error:
搜索该隐秘错误会导致许多结果,提示MultiDex
是罪魁祸首,以及如何处理此问题.为了研究的缘故,我将链接一些线程:
Googling this cryptic error results in a number of results suggesting MultiDex
to be the culprit, and how to handle this. I'll link some threads for research's sake:
Android 3.1.1-无法解决以下问题:Lcom/google/android/gms/common/internal/zzbq;
找不到类"com.google.android.gms.common.internal.zzbq"在路径上:DexPathList
(链接到以前的结果)
Didn't find class "com.google.android.gms.common.internal.zzbq" on path: DexPathList
(links to previous result)
一种解决方案,即如果名称包含multidex
到12.0.1
版本,则将use version
覆盖为com.google.android.gms
:
One of the solutions, namely overriding use version
for com.google.android.gms
if name contains multidex
to version 12.0.1
works for debug
builds:
在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
版本完全不同的问题:
However, this causes completely different issues for production
builds:
所有这些都说"XXX:17.0.1要求",所以我尝试了details.useVersion "17.0.1"
,但这导致了类似的问题:
All of these are saying "Required by XXX:17.0.1", so I tried details.useVersion "17.0.1"
, but that resulted in a similar issue:
其中一些模块的版本为17.0.1
,而其他模块的版本为17.0.2
或17.0.0
,因此严格的use version X.Y.Z
不适用于 release
构建.
Some of these modules have version 17.0.1
, while others are at 17.0.2
or 17.0.0
, so a strict use version X.Y.Z
will not work for release
build.
如果我删除此subProjects { ... }
声明并尝试按照其他答案中的建议启用MultiDex
:
If I remove this subProjects { ... }
declaration and attempt to enable MultiDex
as suggested in other answers:
在android/app/build.gradle
中:
android {
defaultConfig {
...
multiDexEnabled true
}
}
dependencies {
...
implementation 'com.android.support:multidex:1.0.3'
}
对于debug
和release
版本,这都会导致相同的错误,并且有一些额外的谷歌搜索发现SDK版本> 27.0.0
不需要MultiDex
(看起来正在使用28.0.0
/28.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
)
整整一天我一直在为此而努力,却没有取得任何进展.有人见过这个问题与React Native 0.60有关吗?
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?
注意:在我的项目中有几个正在使用这些com.google.android.gms
的插件,即:
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-background-geolocation
implementation "com.google.android.gms:play-services-location:$playServicesLocationVersion"
-
generalImplementation "com.google.android.gms:play-services-vision:$googlePlayServicesVisionVersion"
-
implementation "com.google.android.gms:play-services-gcm:${safeExtGet('googlePlayServicesVersion', '16.1.0')}"
推荐答案
解决方案是对Android
.aab
和.apk
文件使用新的包/构建过程,如React Native文档所示.当前引发错误的过程如下: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`)
成功后,它会生成
.apk
文件并将其安装在设备上,类似于直接从Play商店下载/安装.如上所述,构建过程中的各种错误阻止了这种情况.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文档建议使用一组不同的命令来生成
.aab
文件,然后使用.apk
: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
完整的详细信息可以在 https://facebook.github.io/react-native/docs/signed-apk-android#generating-the-release-apk .自上次实施以来,有关生成Signed APK的信息.
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.
使用这种方法,会生成
.aab
和.apk
文件并将其安装在设备上,但是缺少ic_launcher_rounded
会引起另一个问题.参见 React Native 0.60-缺少ic_launcher_round释放捆绑/构建以获取详细信息.允许时将问题标记为已结束.Using this approach,
.aab
and.apk
files are generated and installed on device, but another issue arises in lack ofic_launcher_rounded
. See React Native 0.60 - ic_launcher_round missing for Release Bundle/Build for details. Marking question as closed when allowed.这篇关于React Native 0.60-无法运行带有react-native run-android的应用程序:java.lang.NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
-