问题
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
Results in a debug
build that successfully installs on my connected app, but crashes upon opening with the following error:
FATAL EXCEPTION: main
Process: com.myApp, PID: XXXX
java.lang.NoClassDefFoundError: Failed resolution of:
Lcom/google/android/gms/common/internal/zzbq
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 - Failed resolution of: Lcom/google/android/gms/common/internal/zzbq;
Didn't find class "com.google.android.gms.common.internal.zzbq" on path: DexPathList
(links to previous result)
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:
In 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"
}
}
}
}
However, this causes completely different issues for production
builds:
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
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:
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
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.
If I remove this subProjects { ... }
declaration and attempt to enable MultiDex
as suggested in other answers:
In 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')}"
回答1:
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.
来源:https://stackoverflow.com/questions/57733597/react-native-0-60-unable-to-run-app-with-react-native-run-android-java-lang-n