我正在开发一个应用,其中使用 firebase
作为 BaaS
。
问题是我收到此错误:引起:java.lang.RuntimeException:未找到 Android 类。您是否在这一行使用 firebase-client-android Artifact ?
Firebase.setAndroidContext(this);
。
这是 FirebaseApplication.java
文件的代码:
public class FirebaseApplication extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
Firebase.setAndroidContext(this);
}
}
这是build.gradle
文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.abc.xyz"
minSdkVersion 16
targetSdkVersion 23
versionCode 5
versionName "0.4"
multiDexEnabled true;
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile 'com.google.android.gms:play-services-maps:9.0.1'
compile 'com.google.android.gms:play-services-plus:9.0.1'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.android.gms:play-services-location:9.0.1'
compile 'com.firebase:geofire:1.1.0'
compile 'com.google.firebase:firebase-database:9.0.1'
compile 'com.google.firebase:firebase-core:9.0.1'
compile 'com.google.firebase:firebase-auth:9.0.1'
compile 'io.github.yavski:fab-speed-dial:1.0.4'
compile 'com.google.gms:google-services:3.0.0'
}
apply plugin: 'com.google.gms.google-services'
我无法找出这里的问题。
最佳答案
您正在使用 GeoFire 1.1.0 导入的旧版 Firebase(您也应该从 GeoFire 1.1.0 迁移到 Geofire 2.X)。
而不是:
Firebase.setAndroidContext(this);
用途:
FirebaseApp.initializeApp(this, FirebaseOptions.fromResource(this));
关于java - 由 : java. lang.RuntimeException : Android classes not found error. 引起 是什么原因导致的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37592253/