这些天我遇到一个问题,不允许我在 Android 设备上运行 React Native 项目,它一启动就崩溃。相反,它在 iOS 设备上运行正常。 这是一个复杂的项目,有很多人参与其中,因此很难完整跟踪多年来的所有进展。
这是错误日志:
FATAL EXCEPTION: Firebase Blocking Thread #0
Process: com.app.MyApp, PID: 15882
java.lang.NoSuchMethodError: No static method checkNotGoogleApiHandlerThread()V in class Lcom/google/android/gms/common/internal/Preconditions; or its super classes (declaration of 'com.google.android.gms.common.internal.Preconditions' appears in /data/app/~~1MEi9R6kd8rP9d1okoXlBg==/com.app.MyApp-Zns5nVqwixkl4DB8j_rd5A==/base.apk)
at com.google.android.gms.tasks.Tasks.await(com.google.android.gms:play-services-tasks@@18.1.0:2)
at com.google.firebase.installations.remote.FirebaseInstallationServiceClient.openHttpURLConnection(FirebaseInstallationServiceClient.java:487)
at com.google.firebase.installations.remote.FirebaseInstallationServiceClient.createFirebaseInstallation(FirebaseInstallationServiceClient.java:163)
at com.google.firebase.installations.FirebaseInstallations.registerFidWithServer(FirebaseInstallations.java:533)
at com.google.firebase.installations.FirebaseInstallations.doNetworkCallIfNecessary(FirebaseInstallations.java:387)
at com.google.firebase.installations.FirebaseInstallations.lambda$doRegistrationOrRefresh$3$FirebaseInstallations(FirebaseInstallations.java:372)
at com.google.firebase.installations.-$$Lambda$FirebaseInstallations$Kl2wdAe5utVajeTmV5LyfWUz3Bo.run(Unknown Source:4)
at com.google.firebase.concurrent.SequentialExecutor$1.run(SequentialExecutor.java:117)
at com.google.firebase.concurrent.SequentialExecutor$QueueWorker.workOnQueue(SequentialExecutor.java:229)
at com.google.firebase.concurrent.SequentialExecutor$QueueWorker.run(SequentialExecutor.java:174)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at com.google.firebase.concurrent.CustomThreadFactory.lambda$newThread$0$CustomThreadFactory(CustomThreadFactory.java:47)
at com.google.firebase.concurrent.-$$Lambda$CustomThreadFactory$25wFMnJXuxCXflRCTG3ggSOiDOE.run(Unknown Source:4)
at java.lang.Thread.run(Thread.java:1012)
这是一个从2024年5月开始就出现的问题,在此之前它没有给出任何类型的故障。 我认为这与 firebase 推送通知的使用有关,也许某些库不再兼容,但我没有成功找到工作组合。
我还附上了 build.gradle 文件
android/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 33
targetSdkVersion = 33
ndkVersion = "21.4.7075529"
googlePlayServicesVersion = "17.0.0"
supportLibVersion = "30.0.0"
//firebaseVersion = "17.3.4" // default: "+"
firebaseMessagingVersion = "+" // default: "+"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath('com.android.tools.build:gradle:4.2.2')
classpath('com.google.gms:google-services:4.3.3')
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
maven { url 'https://www.jitpack.io' }
}
}
android/app/build.gradle
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
enableHermes: false, // clean and rebuild if changing
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
/**
* The preferred build flavor of JavaScriptCore.
*
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
/**
* Architectures to build native code for in debug.
*/
def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures")
android {
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "com.app.MyApp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1087
versionName "2.10"
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
if (nativeArchitectures) {
ndk {
abiFilters nativeArchitectures.split(',')
}
}
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
//if release for play store
//signingConfig signingConfigs.release
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2,]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
packagingOptions {
exclude "META-INF/DEPENDENCIES"
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation ("androidx.appcompat:appcompat:1.3.1") {
version {
strictly '1.3.1'
}
}
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
compile (project(':react-native-push-notification')) { exclude group: 'com.facebook.react', module: 'react-native' }
compile project(':RNMail')
//implementation ('com.google.firebase:firebase-analytics:17.3.0') { exclude group: 'com.google.firebase', module: 'firebase-iid' }
}
apply plugin: 'com.google.gms.google-services'
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.implementation
into 'libs'
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
configurations.all {
resolutionStrategy.force "com.google.android.gms:play-services-gcm:${rootProject.googlePlayServicesVersion}", "com.google.android.gms:play-services-basement:15.0.1"
}
我尝试在 android/build.gradle 中使用和同步不同版本的“googlePlayServicesVersion”(“11.8.0”,“17.0.2”,“18.1.0”,...),使用不同版本的“buildToolsVersion”在android/build.gradle中,在android/build.gradle中使用不同版本的“firebaseMessagingVersion”,使用不同的JDK,更新Android Studio“2023.3.1”,...
期望: 在 Android 设备上运行该项目。
请帮忙:(
尝试删除
"com.google.android.gms:play-services-basement:15.0.1"
从
configurations.all
或将其版本更改为 18.3.0