2017-10-10 116 views
0

我試着用'App-id'和'Add Unit id'以及簽名APK上的實際id來測試。 添加不會同時顯示兩次。 我得到這個警告在logcat中:AdMob add not not up on android

10-10 15:17:53.308 6601-7082/com.babygameseeepe.shreyak.babygames W/Ads: Invoke Firebase method getInstance error. 
    java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.measurement.AppMeasurement" on path: DexPathList[[zip file "/data/app/com.babygameseeepe.shreyak.babygames-1/base.apk"],nativeLibraryDirectories=[/data/app/com.babygameseeepe.shreyak.babygames-1/lib/arm, /vendor/lib, /system/lib]] 
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469) 
    at com.google.android.gms.ads.internal.scionintegration.b.a(:[email protected]:167) 
                                          ... 13 more 

這是我實現:

protected void onCreate(Bundle savedInstanceState) { 
-- 
-- 
MobileAds.initialize(this, "~My-App-Id~"); 
mAdView = (AdView) findViewById(R.id.adView); 
AdRequest adRequest = new AdRequest.Builder().build(); 
mAdView.loadAd(adRequest); 
} 

在XML:

<com.google.android.gms.ads.AdView 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/adView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_alignParentBottom="true" 
    ads:adSize="BANNER" 
    ads:adUnitId="~My-add-unit-id~"> 
</com.google.android.gms.ads.AdView> 

權限:

<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 

搖籃(項目級):

allprojects { 
repositories { 
    jcenter() 
    maven { 
     url "https://maven.google.com" 
    } 
} 
} 

搖籃(應用層):

apply plugin: 'com.android.application' 
android { 
    compileSdkVersion 25 
    buildToolsVersion "26.0.2" 
    defaultConfig { 
     applicationId "com.babygameseeepe.shreyak.babygames" 
     minSdkVersion 15 
     targetSdkVersion 25 
     versionCode 5 
     versionName "1.4.2" 
     testInstrumentationRunner  "android.support.test.runner.AndroidJUnitRunner" 
     multiDexEnabled true 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
    } 
} 

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' 
    }) 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 

    compile 'com.google.android.gms:play-services-ads:11.4.0' 
    testCompile 'junit:junit:4.12' 
} 

我按照this鏈路實現附加(不火力)。請幫忙。

+0

這不是你的AddMob的問題 –

+0

@SushinPv我做錯了什麼? –

+0

查看下面的新答案 –

回答

0

應用搖籃

defaultConfig { 
    ... 

    // Enabling multidex support. 
    multiDexEnabled true 
} 

轉到添加該代碼Build選項,然後

  1. Clean Project
  2. Rebuild Project

這將工作。

如果它不起作用。你應用搖籃的末尾添加這些代碼

dependencies { 
    //All your dependencies 
} 

configurations.all { 
    resolutionStrategy.eachDependency { DependencyResolveDetails details -> 
     def requested = details.requested 
     if (requested.group == 'com.android.support') { 
      if (!requested.name.startsWith("multidex")) { 
       details.useVersion '26.+' 
      } 
     } 
    } 
} 
-1

我認爲錯誤是不是在你的代碼,它可以在XML文件中,

  1. 儘量讓AdView的分層結構中的主要元素
  2. 刪除並重新安裝應用程序。
  3. 如果廣告ID是新的,則需要5分鐘--3.4小時才能顯示實際的廣告。還要確保你已經刪除了測試設備ID。
+0

首先,我只是要求卸載它,以便如果有一些緩存不允許它查看廣告,它可能會被刪除,以及在您的手機上安裝和重新安裝應用程序有什麼大不了的。 –