我的环境:
React Native:0.50.4
Android Studio:3.1.1
Gradle:4.6
设备:Android模拟器(任何Android操作系统)
我正在更新我当前的反应原生应用以开始使用Firebase。我正在使用react-native-firebase
包来集成它们,但我非常肯定这不是问题,因为我的问题出现在我开始处理之前。
以下是我的一些来源:
build.gradle
:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.2'
}
}
allprojects {
repositories {
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 {
url 'https://maven.google.com'
}
google()
}
}
“应用/ build.gradle`:
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 23
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.ourdailystrength.mobile.android"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
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
}
}
}
}
dependencies {
//compile(project(':react-native-firebase')) {
// transitive = false
//}
compile project(':react-native-config')
compile project(':react-native-i18n')
compile project(':react-native-vector-icons')
compile project(':react-native-device-info')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:0.50.4" // From node_modules
// firebase modules
implementation "com.google.android.gms:play-services-base:12.0.1"
implementation "com.google.firebase:firebase-core:12.0.1"
}
// 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.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
一旦我构建并运行应用程序,我就会收到以下错误:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzbq;
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source:2)
at android.app.ActivityThread.installProvider(ActivityThread.java:6378)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5939)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5856)
at android.app.ActivityThread.access$1100(ActivityThread.java:193)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1623)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzbq" on path: DexPathList[[zip file "/data/app/com.ourdailystrength.mobile.android-mFoP1bOjnUTgeG_cDvnVkg==/base.apk"],nativeLibraryDirectories=[/data/app/com.ourdailystrength.mobile.android-mFoP1bOjnUTgeG_cDvnVkg==/lib/x86, /system/fake-libs, /data/app/com.ourdailystrength.mobile.android-mFoP1bOjnUTgeG_cDvnVkg==/base.apk!/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source:2)
at android.app.ActivityThread.installProvider(ActivityThread.java:6378)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5939)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5856)
at android.app.ActivityThread.access$1100(ActivityThread.java:193)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1623)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
我确实尝试从12.0.1
升级到15.0.0
并让它构建并运行良好,但是当向Firebase发送消息时,它抱怨Google Play服务已过时。得到了这个错误:
W/GooglePlayServicesUtil: Google Play services out of date. Requires 12451000 but found 12446024
W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
V/FA: Processing queued up service tasks: 1
E/FA: Discarding data. Failed to send event to service
我是在Android P上运行的,所以我认为Google Play服务不会过时。我无法找到谷歌在哪里发布谷歌播放服务的版本,因为我有预感12.4.51.000尚不存在。
我试图找到答案,但没有人帮助过。一切都会有所帮助。谢谢!
答案 0 :(得分:-2)
我找到了解决方案。
将所有内容更新为依赖项中的15.0.0
。是的,它将继续为您提供过时谷歌播放服务的错误,但没关系。
创建一个安装了Google Play商店的新模拟器(目前,我认为它只是Nexus 5和5X)。
打开模拟器并更新Google Play服务。您需要先打开Google Play并登录。完成后,您应该收到更新Google Play服务的通知。
完成更新后,您可以检查设置,看它是什么版本,以及它是否足够新(应该是什么)。
卸载应用并重新安装应用。它应该现在正在运作。