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.
背景交代:
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 导致,采用第二种方案完美解决真机问题;
解决方案:
为尊重作者,笔者摘抄如下
|
Follow these steps:
- Go to Android SDK Manager
- Go to Extra
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),一起讨论吧。