Java.lang.NoClassDefFoundError:解析失败:Lcom/google/firebase/FirebaseApp
这是一个本地项目。在Android Studio Emulator中成功构建后,我出现了一个错误: java.lang.NoClassDefFoundError:解析失败: Lcom/google/firebase/FirebaseApp 我的文件: package.json:Java.lang.NoClassDefFoundError:解析失败:Lcom/google/firebase/FirebaseApp,java,android,firebase,react-native,react-native-firebase,Java,Android,Firebase,React Native,React Native Firebase,这是一个本地项目。在Android Studio Emulator中成功构建后,我出现了一个错误: java.lang.NoClassDefFoundError:解析失败: Lcom/google/firebase/FirebaseApp 我的文件: package.json: ... "react-native": "^0.55.3", "react-native-camera": "1.1.2", "react-native-check-box": "^2.1.0", "react-nati
...
"react-native": "^0.55.3",
"react-native-camera": "1.1.2",
"react-native-check-box": "^2.1.0",
"react-native-extended-stylesheet": "^0.8.1",
"react-native-firebase": "^4.2.0",
"react-native-geocoder": "^0.5.0",
"react-native-git-upgrade": "^0.2.7",
"react-native-htmlview": "^0.12.1",
"react-native-image-picker": "^0.26.10",
"react-native-linear-gradient": "^2.4.0",
"react-native-local-storage": "^1.5.2",
"react-native-maps": "^0.21.0",
"react-native-modal": "^5.4.0",
"react-native-modal-dropdown": "^0.6.1",
"react-native-read-more-text": "^1.0.0",
"react-native-router-flux": "^4.0.0-beta.27",
"react-native-svg-image": "^2.0.1",
"react-native-text-input-mask": "^0.7.0",
...
...
android {
compileSdkVersion 27
buildToolsVersion "27.0.1"
defaultConfig {
applicationId "com.something.anything"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
multiDexEnabled true
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
signingConfig signingConfigs.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-geocoder')
compile(project(':react-native-maps')) {
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
exclude group: 'com.google.android.gms', module: 'play-services-location'
}
compile 'com.google.android.gms:play-services-base:15.+'
compile 'com.google.android.gms:play-services-maps:15.+'
compile 'com.google.android.gms:play-services-location:15.+'
compile (project(':react-native-camera')) {
exclude group: "com.google.android.gms"
compile 'com.android.support:exifinterface:25.+'
compile ('com.google.android.gms:play-services-vision:12.0.1') {
force = true
}
}
compile project(':react-native-text-input-mask')
compile project(':react-native-linear-gradient')
compile project(':react-native-image-picker')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
}
}
// 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'
}
android/app/build.gradle:
...
"react-native": "^0.55.3",
"react-native-camera": "1.1.2",
"react-native-check-box": "^2.1.0",
"react-native-extended-stylesheet": "^0.8.1",
"react-native-firebase": "^4.2.0",
"react-native-geocoder": "^0.5.0",
"react-native-git-upgrade": "^0.2.7",
"react-native-htmlview": "^0.12.1",
"react-native-image-picker": "^0.26.10",
"react-native-linear-gradient": "^2.4.0",
"react-native-local-storage": "^1.5.2",
"react-native-maps": "^0.21.0",
"react-native-modal": "^5.4.0",
"react-native-modal-dropdown": "^0.6.1",
"react-native-read-more-text": "^1.0.0",
"react-native-router-flux": "^4.0.0-beta.27",
"react-native-svg-image": "^2.0.1",
"react-native-text-input-mask": "^0.7.0",
...
...
android {
compileSdkVersion 27
buildToolsVersion "27.0.1"
defaultConfig {
applicationId "com.something.anything"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
multiDexEnabled true
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
signingConfig signingConfigs.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-geocoder')
compile(project(':react-native-maps')) {
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
exclude group: 'com.google.android.gms', module: 'play-services-location'
}
compile 'com.google.android.gms:play-services-base:15.+'
compile 'com.google.android.gms:play-services-maps:15.+'
compile 'com.google.android.gms:play-services-location:15.+'
compile (project(':react-native-camera')) {
exclude group: "com.google.android.gms"
compile 'com.android.support:exifinterface:25.+'
compile ('com.google.android.gms:play-services-vision:12.0.1') {
force = true
}
}
compile project(':react-native-text-input-mask')
compile project(':react-native-linear-gradient')
compile project(':react-native-image-picker')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
}
}
// 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'
}
android/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.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
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"
}
}
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex')
) {
details.useVersion "27.1.0"
}
}
}
}
我尝试了很多解决方案,但没有任何效果。面临同样的问题。然后我发现我错过了将Firebase与Android项目集成的一组重要说明: 以下是该文档中有助于我的案例的步骤摘要:
googleservices.json
,并将其放入您的android/app/
目录classpath'com.google.gms:googleservices:4.1.0'
添加到根级别build.gradle
config的buildscript->dependencies
部分;将google()
添加到同一文件的allprojects->repositories
部分implementation'com.google.firebase:firebase核心:16.0.3'
添加到应用程序模块build.gradle
文件的依赖项部分;在同一文件的最底部添加apply插件:“com.google.gms.google服务”
在app gradle文件中更改了最新的firebase消息传递google依赖项,并在同一版本中修改了其他依赖项。现在工作很好
在我的例子中,我忘记在MainApplication.java中注释数据库包
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new AsyncStoragePackage(),
new RNCameraPackage(),
new VectorIconsPackage(),
new RNGestureHandlerPackage(),
new RNFirebasePackage(),
// add/remove these packages as appropriate
//new RNFirebaseAdMobPackage(),
new RNFirebaseAnalyticsPackage(),
//new RNFirebaseAuthPackage(),
// new RNFirebaseRemoteConfigPackage(),
new RNFirebaseCrashlyticsPackage(),
// new RNFirebaseDatabasePackage(), <==== Comment this package
// new RNFirebaseFirestorePackage(),
// new RNFirebaseFunctionsPackage(),
new RNFirebaseInstanceIdPackage(),
// new RNFirebaseInvitesPackage(),
new RNFirebaseLinksPackage(),
new RNFirebaseMessagingPackage(),
new RNFirebaseNotificationsPackage(),
new RNFirebasePerformancePackage()
// new RNFirebaseStoragePackage()
);
}
@覆盖
受保护的列表getPackages(){
返回数组.asList(
新建MainReactPackage(),
新建AsyncStoragePackage(),
新的RNCameraPackage(),
新的VectorConsPackage(),
新RNGestureHandlerPackage(),
新的RNFirebasePackage(),
//根据需要添加/删除这些包
//新的RNFirebaseAdMobPackage(),
新的RNFirebaseAnalyticsPackage(),
//新的RNFirebaseAuthPackage(),
//新的RNFirebaseRemoteConfigPackage(),
新的RNFirebaseCrashlyticPackage(),
//新的RNFirebaseDatabasePackage(),我遇到了同样的问题。您必须在pakage.json文件中更改react本机firebase版本。我从这里找到了解决方案
在您的android/app/build.gradle上
根据依赖项再添加一个实现:
...
dependencies {
implementation "com.google.firebase:firebase-auth:17.0.0"
...
}
所涉及的依赖关系可能存在一些问题
就我而言,在应用程序级别build.gradle
dependencies{
implementation 'com.google.firebase:firebase-auth:17.0.0'
implementation 'com.firebaseui:firebase-ui-database:6.0.2'
...
}
在gradle.properties文件中,尝试添加::
android.enableJetifier = true
android.useAndroidX = true
如果您在Flatter中遇到此问题,请在android/app/build.gradle中添加此依赖项,然后运行main.dart。无需在ListView中添加任何类型的控制器。如果您在该页面上使用ListView。如果您使用Firebase,请在Dependencies中添加此依赖项
实现“com.google.firebase:firebase auth:19.3.0”
更新您的firebase库
例如,如果您的应用程序使用firebase auth,谷歌为其提供最新版本的文档,请将其粘贴到build.gradle
您的Firebase助手在Android Studio中添加的库通常比较旧。使用相同版本的play service库。也不要在依赖项中使用+运算符。找到的版本为服务库:15.+'
,vision:12.0.1
@alex khanenya您找到解决方案了吗?我有相同的错误。Thanks@alex- Khannya,请考虑如果答案解决了问题,就表示答案已被接受。