簡體   English   中英

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

在一個漫長的周末之前的周五晚,我在運行react-native應用程序時遇到了問題。 當前版本是0.60 (最新),並運行命令

react-native run-android

生成一個debug版本,該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;

在路徑:DexPathList上找不到類“ com.google.android.gms.common.internal.zzbq”
(鏈接到以前的結果)

解決方案之一,即如果名稱包含12.0.1版的multidex ,則覆蓋com.google.android.gms use version 可用於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-表型: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

其中一些模塊的版本為17.0.1 ,而其他模塊的版本為17.0.217.0.0 ,因此嚴格use version XYZ不適用於release版本。

如果我刪除此subProjects { ... }聲明並嘗試按照其他答案中的建議啟用MultiDex

android/app/build.gradle

android {
    defaultConfig {
        ...
        multiDexEnabled true
    }
}
dependencies {
    ...
    implementation 'com.android.support:multidex:1.0.3'
}

這導致了同樣的錯誤兩種debugrelease版本,以及額外的谷歌搜索一點點揭露說MultiDex不需要SDK版本> 27.0.0 (看起來是使用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文件使用新的包/構建過程,如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商店下載/安裝。 如上所述,構建過程中的各種錯誤阻止了這種情況。

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中找到。 自先前實施以來,已包含有關生成Signed APK的信息。

使用這種方法,可以生成.aab.apk文件並將其安裝在設備上,但是由於缺少ic_launcher_rounded出現了另一個問題。 有關詳細信息,請參見Release Bundle / Build缺少React Native 0.60-ic_launcher_round 允許時將問題標記為已關閉。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM