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),一起讨论吧。



当遇到 “Could not find com.google.firebase:firebase-app-unity:13.4.0” 问题时,可尝试以下解决方案: ### 检查仓库配置 确保项目的 `build.gradle` 文件中正确配置了 Google Maven 仓库。在项目根目录的 `build.gradle` 中添加或确认以下内容: ```groovy allprojects { repositories { google() jcenter() // 如果使用 } } ``` ### 检查版本号 确认 `13.4.0` 版本是否存在。可前往 [Maven Central](https://search.maven.org/) 或 [Google Maven Repository](https://maven.google.com/) 搜索该版本。若不存在,可尝试使用其他可用版本。例如,在 `build.gradle` 中更新依赖版本: ```groovy dependencies { implementation 'com.google.firebase:firebase-app-unity:合适的版本号' } ``` ### 同步 Gradle 项目 在 Android Studio 中,点击 “File” -> “Sync Project with Gradle Files” 强制同步项目,确保 Gradle 重新下载依赖。 ### 清理和重建项目 在 Android Studio 中,选择 “Build” -> “Clean Project”,然后选择 “Build” -> “Rebuild Project”,清除旧的构建文件并重新构建项目。 ### 检查网络连接 确保网络连接正常,因为 Gradle 需要从远程仓库下载依赖。若使用了代理,需确保代理配置正确。 ### 检查本地缓存 有时本地 Gradle 缓存可能损坏。可删除 `~/.gradle/caches` 目录下的内容,然后重新同步项目。 ```bash rm -rf ~/.gradle/caches ``` ### 检查 Unity 包管理器 若在 Unity 项目中使用该依赖,可通过 Unity 的包管理器检查和更新 Firebase 相关包。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

群鸿

感谢认可,多谢打赏。

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

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

打赏作者

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

抵扣说明:

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

余额充值