Could not find class 'com.google.firebase.FirebaseOptions' 解决方案

背景交代:

1,加入谷歌广告依赖;

2,加入谷歌分析依赖;

奇葩问题:

1,模拟器正常运行(可能是采用了科学上网吧);

2,真机报错提示:Could not find class 'com.google.firebase.FirebaseOptions', referenced from method com.google.firebase.FirebaseApp.<init>

如下图:


解决过程:

1,百度半小时,基本无用,也简单明白了为什么,可能是依赖包没有安装,更新后依然无效;

2,科学上网直接stackoverflow,问题解决,笔者是自定义了:ITApplication extends Application 导致,采用第二种方案完美解决真机问题;


解决方案:

为尊重作者,笔者摘抄如下

 

This bug is reported with newer versions mostly arround Revision 28,29 and its resolved in newer Play services versions so very first if you having this issue then make sure you have updated version of Google Play service in your Android studio.


Follow these steps:

  1. Go to Android SDK Manager
  2. Go to Extra

enter image description here

And update it to version 30 or later.

Then if you are using MultiDex in your Application then please use it only if it's compulsory.

Make sure you have follow these steps when integrating MultiDex.

In you App level Build.Gradle

 defaultConfig {
        applicationId "com.reversebits.tapanhp.saffer"
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

Apply MultiDex dependency in dependencies

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    wearApp project(':wear')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.android.support:multidex:1.0.1'
}

Then inside your AndroidMenifest.xml file make sure that Application tag have name of MultiDexApplication.

<application
        android:name="android.support.multidex.MultiDexApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

Note

if you have custom Application class and using it in your menifest file then you can initialize multidex in your Application class as follows,

public class AppClass extends Application {
    private static Context context;
    private static AppClass mInstance;

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

}


总结:凡事都可能有原因,只有你想不到,没有你办不到,适当的搜索工具,真的可以事半功倍,Android中国开发者,加入QQ群(361871827),一起讨论吧。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

群鸿

感谢认可,多谢打赏。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值