これはReact=ネイティブプロジェクトです。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-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/app/build.gradle:
...
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プロジェクトと統合するための重要な一連の指示を逃したことがわかりました: https://firebase.google.com/docs/Android/setup#add_firebase_to_your_app
私の場合に役立ったそのドキュメントの手順の概要は次のとおりです。
google-services.json
_を生成し、それを_Android/app/
_ディレクトリに配置します。classpath 'com.google.gms:google-services:4.1.0'
_ configの_buildscript -> dependencies
_セクションに_build.gradle
_を追加します。 google()
を同じファイルの_allprogects -> repositories
_セクションに追加します。implementation 'com.google.firebase:firebase-core:16.0.3'
_ファイルのdependencies
セクションに_build.gradle
_を追加します。同じファイルの一番下に_apply plugin: 'com.google.gms.google-services'
_を追加します。Android/app/build.gradle
で、依存関係にもう1つの実装を追加します。
...
dependencies {
implementation "com.google.firebase:firebase-auth:17.0.0"
...
}
私の場合、MainApplication.JavaのDatabase Packageにコメントするのを忘れていました
@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()
);
}
同じ問題に直面しました。 pakage.jsonファイルでreact-native-firebaseのバージョンを変更する必要があります。ここから解決策を見つけました
googleの最新のfirebase-messaging依存関係を変更し、アプリgradleファイルの同じバージョンの他の依存関係も変更しました。今はうまくいっている
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'com.google.firebase:firebase-auth:17.0.0'
implementation 'com.google.firebase:firebase-messaging:18.0.0'
}