背景交代:
1,加入谷歌广告依赖;
2,加入谷歌分析依赖;
奇葩问题:
1,模拟器正常运行(可能是采用了科学上网吧);
2,真机报错提示:Could not find class 'com.google.firebase.FirebaseOptions', referenced from method com.google.firebase.FirebaseApp.
如下图:
解决过程:
1,百度半小时,基本无用,也简单明白了为什么,可能是依赖包没有安装,更新后依然无效;
2,科学上网直接stackoverflow,问题解决,笔者是自定义了:ITApplication extends Application 导致,采用第二种方案完美解决真机问题;
解决方案:
为尊重作者,笔者摘抄如下
Follow these steps:
Go to Android SDK Manager
Go to Extra
And update it toversion 30or later.
Then ifyou are using MultiDexin your Application then please use it only if it's compulsory.
Make sure you have follow these steps when integrating MultiDex.
In youApp level Build.Gradle
defaultConfig{applicationId"com.reversebits.tapanhp.saffer"minSdkVersion17targetSdkVersion23versionCode1versionName"1.0"multiDexEnabledtrue}
Apply MultiDex dependencyindependencies
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 yourAndroidMenifest.xmlfile make sure thatApplication tag have name of MultiDexApplication.
Note
if you have custom Application classand using it in your menifest file then you caninitialize multidex in your Application classas follows,
publicclassAppClassextendsApplication{privatestaticContextcontext;privatestaticAppClassmInstance;@OverrideprotectedvoidattachBaseContext(Contextbase){super.attachBaseContext(base);MultiDex.install(this);}}
总结:凡事都可能有原因,只有你想不到,没有你办不到,适当的搜索工具,真的可以事半功倍,Android中国开发者,加入QQ群(361871827),一起讨论吧。