React Native 0.60-无法运行带有react-native run-android的应用程序:java.lang.NoClassDefFoundError [英] React Native 0.60 - Unable to Run App with react-native run-android: java.lang.NoClassDefFoundError

查看:146
本文介绍了React Native 0.60-无法运行带有react-native run-android的应用程序:java.lang.NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个漫长的周末之前的周五晚,我在运行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:

致命异常:主要
流程:com.myApp,PID:XXXX
java.lang.NoClassDefFoundError:无法解决以下问题:
Lcom/google/android/gms/common/internal/zzbq

FATAL EXCEPTION: main
Process: com.myApp, PID: XXXX
java.lang.NoClassDefFoundError: Failed resolution of:
Lcom/google/android/gms/common/internal/zzbq

搜索该隐秘错误会导致许多结果,提示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)

一种解决方案,即如果名称包含multidex12.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:

找不到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-表型:12.0.1
找不到com.google.android.gms:play-services-stats:12.0.1

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

所有这些都说"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:

找不到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

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.217.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'
}

对于debugrelease版本,这都会导致相同的错误,并且有一些额外的谷歌搜索发现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 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.

      这篇关于React Native 0.60-无法运行带有react-native run-android的应用程序:java.lang.NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆