我想在我的Android应用中添加AdView。 该应用正在使用" Firebase - Auth,实时数据库"," Realm数据库"。
我正在尝试按照以下链接添加AdView。 https://firebase.google.com/docs/admob/android/quick-start
但当我调用MobileAds.initialize()时,发生了错误。
04-09 02:47:09.937 10717-10717/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pline.richdiary, PID: 10717
java.lang.IncompatibleClassChangeError: Superclass com.google.android.gms.dynamic.zzg of com.google.android.gms.internal.zzdx is declared final (declaration of 'com.google.android.gms.internal.zzdx' appears in /data/app/com.pline.richdiary-1/split_lib_dependencies_apk.apk:classes31.dex)
at com.google.android.gms.internal.zzeh.zzeP(Unknown Source)
at com.google.android.gms.internal.zzfb.zza(Unknown Source)
at com.google.android.gms.ads.MobileAds.initialize(Unknown Source)
at com.google.android.gms.ads.MobileAds.initialize(Unknown Source)
at com.pline.richdiary.accounts.AccountsFragment.onCreate(AccountsFragment.java:75)
at android.support.v4.app.Fragment.performCreate(Fragment.java:2177)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1244)
at android.support.v4.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1080)
at android.support.v4.app.FragmentTransition.calculateFragments(FragmentTransition.java:971)
at android.support.v4.app.FragmentTransition.startTransitions(FragmentTransition.java:95)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2143)
at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2098)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2008)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:710)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
以下是AccountsFragment.java
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
public class AccountsFragment extends Fragment implements AccountsContract.View {
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate()");
super.onCreate(savedInstanceState);
MobileAds.initialize(getContext(), "ca-app-pub-2962069012725032~2391520900");
}
以下是我的gradle依赖项。
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
// Dependencies for local unit tests
testCompile "junit:junit:$rootProject.ext.junitVersion"
testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion"
testCompile "org.powermock:powermock-module-junit4:$rootProject.ext.powerMockito"
testCompile "org.powermock:powermock-api-mockito:$rootProject.ext.powerMockito"
// Google
compile 'com.google.firebase:firebase-config:10.2.0'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-auth:10.2.0'
compile 'com.google.firebase:firebase-ads:10.0.1'
compile 'com.google.firebase:firebase-database:10.2.0'
compile 'com.google.firebase:firebase-crash:10.0.1'
compile 'com.firebaseui:firebase-ui-database:0.4.1'
compile 'com.google.guava:guava:18.0'
compile 'com.android.support:design:25.1.1'
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:support-v4:25.1.1'
compile 'com.android.support:cardview-v7:25.1.1'
compile 'com.google.android.gms:play-services-auth:10.2.0'
compile 'com.beardedhen:androidbootstrap:2.3.1'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
provided 'org.projectlombok:lombok:1.12.6'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}
我现在不知道该怎么做。
AppId,Ad-Unit-id在我的AdMob帐户中生成。