我正在创建一个简单的应用程序,该应用程序将使用React-Native-Firebase和React-Native-Maps。在文档安装后,我的地图启动并运行,没有任何问题。之后,我安装了Firebase,并遵循了教程。我在途中遇到了几个错误,但是清理Gradle Build等最终使我获得了"成功"的信息。但是,该应用程序在开始时一直在崩溃。来自Android Studio的LogCat指出了此错误:
FATAL EXCEPTION: create_react_context
Process: com.demoapp, PID: 13267
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/internal/zzbfm;
at com.airbnb.android.react.maps.MapsPackage.createViewManagers(MapsPackage.java:39)
at com.facebook.react.ReactInstanceManager.getOrCreateViewManagers(ReactInstanceManager.java:770)
at com.facebook.react.CoreModulesPackage.createUIManager(CoreModulesPackage.java:170)
at com.facebook.react.CoreModulesPackage.access$200(CoreModulesPackage.java:53)
at com.facebook.react.CoreModulesPackage$7.get(CoreModulesPackage.java:128)
at com.facebook.react.CoreModulesPackage$7.get(CoreModulesPackage.java:125)
at com.facebook.react.LazyReactPackage$2$1.next(LazyReactPackage.java:102)
at com.facebook.react.LazyReactPackage$2$1.next(LazyReactPackage.java:89)
at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:44)
at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1212)
at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1182)
at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1120)
at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:123)
at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:943)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.internal.zzbfm" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.demoapp-0Fn4BfYJM0KChb969SjTxA==/base.apk"],nativeLibraryDirectories=[/data/app/com.demoapp-0Fn4BfYJM0KChb969SjTxA==/lib/x86, /data/app/com.demoapp-0Fn4BfYJM0KChb969SjTxA==/base.apk!/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
这是我的build.gradle
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 27
supportLibVersion = "28.0.0"
googlePlayServicesVersion = "11.8.0"
androidMapsUtilsVersion = "0.5+"
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.7'
distributionUrl = distributionUrl.replace("bin", "all")
}
apply plugin: 'com.google.gms.google-services'
如果这里有必要也是我使用的所有版本的包装 - json文件:
{
"name": "DemoApp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.6.3",
"react-native": "0.58.4",
"react-native-firebase": "^5.2.2",
"react-native-gesture-handler": "^1.0.15",
"react-native-maps": "^0.23.0",
"react-navigation": "^3.2.1"
},
"devDependencies": {
"babel-core": "7.0.0-bridge.0",
"babel-jest": "24.1.0",
"jest": "24.1.0",
"metro-react-native-babel-preset": "0.51.1",
"react-test-renderer": "16.6.3"
},
"jest": {
"preset": "react-native"
}
}
任何帮助将不胜感激!Google Play服务版本错误吗?可能导致这个问题?
编辑:添加Multidex后的完整错误日志。该设备已连接,您可以在CMD运行ADB设备后看到它。
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
> Configure project :
Warning: Please apply google-services plugin at the bottom of the build file.
> Configure project :react-native-firebase
react-native-firebase: using React Native prebuilt binary from C:workspacecopleybrosDemoAppnode_modulesreact-nativeandroid
> Task :app:compileDebugJavaWithJavac
C:workspacecopleybrosDemoAppandroidappsrcmainjavacomdemoappMainApplication.java:4: error: cannot find symbol
import android.app.MultiDexApplication;
^
symbol: class MultiDexApplication
location: package android.app
C:workspacecopleybrosDemoAppandroidappsrcmainjavacomdemoappMainApplication.java:17: error: cannot find symbo
public class MainApplication extends MultiDexApplication implements ReactApplication {
^
symbol: class MultiDexApplication
C:workspacecopleybrosDemoAppandroidappsrcmainjavacomdemoappMainApplication.java:19: error: incompatible types: MainApplication cannot be converted to Application
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
^
C:workspacecopleybrosDemoAppandroidappsrcmainjavacomdemoappMainApplication.java:19: error: cannot find symbol private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
^
symbol: constructor (MainApplication)
C:workspacecopleybrosDemoAppandroidappsrcmainjavacomdemoappMainApplication.java:46: error: method does not override or implement a method from a supertype
@Override
^
C:workspacecopleybrosDemoAppandroidappsrcmainjavacomdemoappMainApplication.java:48: error: cannot find symbol super.onCreate();
^
symbol: variable super
location: class MainApplication
C:workspacecopleybrosDemoAppandroidappsrcmainjavacomdemoappMainApplication.java:49: error: no suitable method found for init(MainApplication,boolean)
SoLoader.init(this, /* native exopackage */ false);
^
method SoLoader.init(Context,int) is not applicable
(argument mismatch; MainApplication cannot be converted to Context)
method SoLoader.init(Context,boolean) is not applicable
(argument mismatch; MainApplication cannot be converted to Context)
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
7 errors
> Task :app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 9s
48 actionable tasks: 1 executed, 47 up-to-date
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
Command failed: gradlew.bat installDebug
Error: Command failed: gradlew.bat installDebug
at checkExecSyncError (child_process.js:601:13)
at Object.execFileSync (child_process.js:621:13)
at runOnAllDevices (C:workspacecopleybrosDemoAppnode_modulesreact-nativelocal-clirunAndroidrunAndroid.js:299:19)
at buildAndRun (C:workspacecopleybrosDemoAppnode_modulesreact-nativelocal-clirunAndroidrunAndroid.js:135:12) at isPackagerRunning.then.result (C:workspacecopleybrosDemoAppnode_modulesreact-nativelocal-clirunAndroidrunAndroid.js:65:12)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
由于Android X,React Antial和Flutter中的大多数开发人员都面临问题。您可以通过此https://developer.android.com/jetpack/androidx/migrate
,或者您可以使用库并构建与27不是28相关的工具版本。
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.internal.zzbfm" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.demoapp-0Fn4BfYJM0KChb969SjTxA==/base.apk"],nativeLibraryDirectories=[/data/app/com.demoapp-0Fn4BfYJM0KChb969SjTxA==/lib/x86, /data/app/com.demoapp-0Fn4BfYJM0KChb969SjTxA==/base.apk!/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
这条线表明这可能是一个DEX问题。您应该为您的应用启用多端支持。
在您的app/build.gradle
中的依赖项中,您必须添加:
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
在您的app/build.gradle
中,您需要在defaultConfig
android {
defaultConfig {
...
multiDexEnabled true
}
...
}
最后,您需要在MainApplication.java
中扩展MultiDexApplication
:
public class MainApplication extends MultiDexApplication implements ReactApplication {
要了解有关Multidex的更多信息,您可以在此处查看文档。
更新
查看您更新的错误消息,似乎您在MainApplication.java
中错误地导入MultiDexApplication
> Task :app:compileDebugJavaWithJavac
C:workspacecopleybrosDemoAppandroidappsrcmainjavacomdemoappMainApplication.java:4: error: cannot find symbol
import android.app.MultiDexApplication;
^
symbol: class MultiDexApplication
location: package android.app
当前您将其作为
import android.app.MultiDexApplication;
,但应该是
import android.support.multidex.MultiDexApplication;
,最终解决了问题:将它们降低到15.0.0
implementation "com.google.android.gms:play-services-base:15.0.0"
implementation "com.google.firebase:firebase-core:15.0.0"
并使用
googlePlayServicesVersion = "15.0.1"
另外,在build.gradle的最底部
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
只有所有这些结合了安德鲁和桑吉夫的答案才能让我到达那里。感谢你们俩的输入!