【问题标题】:App crashes after integrating with Firebase与 Firebase 集成后应用程序崩溃
【发布时间】:2016-09-15 01:54:00
【问题描述】:

我正在构建我的第一个使用 Google Maps API 活动的 Android 应用。它在模拟器上运行良好。但是添加 Firebase 后,它在模拟器上崩溃了:

Unfortunately, MyApp has stopped

查了很多,发现查logcat很有用,显示异常如下:

09-15 03:30:39.836 3541-3541/com.example.googlemapsapi E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: com.google.firebase.FirebaseOptions
    at com.google.firebase.FirebaseApp.zzek(Unknown Source)
    at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:1058)
    at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
    at android.app.ActivityThread.installProvider(ActivityThread.java:4560)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4190)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4132)
    at android.app.ActivityThread.access$1300(ActivityThread.java:130)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)

我已经完成了这些解决方案中的步骤

但问题依然存在。

MapsActivity.java 文件:

package com.example.googlemapsapi;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }


    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        /*LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    */
        LatLng busLocation = new LatLng(37.783879,-122.401254);

        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(busLocation, 12));
        mMap.addMarker(new MarkerOptions()
                .position(busLocation)
                .title("Code the Road Bus")
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.bus)));

    }
}

build.gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
}

app/build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "com.example.googlemapsapi"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
/*
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'

    }
    */
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.google.firebase:firebase-core:9.4.0'
   // compile 'com.firebase:firebase-client-android:2.5.2+'
}
apply plugin: 'com.google.gms.google-services'

我做错了什么? 提前致谢, 塞缪尔·法里德

【问题讨论】:

  • 在您的模拟器上,转到设置/应用程序并点击 Google Play 服务。版本号是 9.4.52 吗?
  • 请在stacktrace的每行开头添加四个空格,以便于阅读。
  • @qbix 是的。

标签: android firebase


【解决方案1】:

请更新播放服务或在真机上试一试,即可。 Check this.

【讨论】:

    【解决方案2】:

    更新您的播放服务库 您的项目类路径是-classpath 'com.google.gms:google-services:3.0.0' 和 依赖是 编译'com.google.android.gms:play-services:9.4.0' 编译'com.google.firebase:firebase-core:9.4.0'

    所以更新你的播放服务库

    【讨论】:

    • 如何更新播放服务库?如果你通过android sdk manager更新google play服务,已经更新了。
    • 更新了 build.gradle 文件:defaultConfig { ... multiDexEnabled true } 依赖项 { compile 'com.android.support:multidex:1.0.0' }
    【解决方案3】:

    对我来说,我的 android 模拟器和 android 设备都崩溃了,因为我在 <project_dir>/<app_module>/build.gradle 中导入了 crashlytics 依赖项,如下所示:implementation 'com.google.firebase:firebase-crashlytics:17.2.1'。注释掉这一行后,我的应用程序停止崩溃。我不确定 crashlytics 导致应用程序崩溃的原因,但我确实在使用和不使用此导入行的情况下对其进行了测试,结果对我来说很有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-27
      • 2016-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多