0

I tried with the test with the 'App-id' and the 'Add Unit id' and the actual ids on signed APK. The add does not show up both times. I get this warn in logcat:

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(:com.google.android.gms.DynamiteModulesA@11518438:167)
                                                                                                                                                            ... 13 more

 

Here is my implementation:

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);
}

In 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>

Permissions:

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

Gradle (project level):

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

Gradle (App level) :

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'
}

I have followed this link to implement the add (without firebase). Please help.

Flying Monkey
  • 669
  • 1
  • 5
  • 13

2 Answers2

0

Add this code in your App Gradle

defaultConfig {
    ...

    // Enabling multidex support.
    multiDexEnabled true
}

Go to Build Options then

  1. Clean Project
  2. Rebuild Project.

This will work.

If it won't work. Add these codes at the end of your App Gradle

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.+'
            }
        }
    }
}
Sushin Pv
  • 1,826
  • 3
  • 22
  • 36
-1

I think the error is not in your code it could be in your xml file,

  1. Try to make the AdView primary element in the hierarchy
  2. Delete and reinstall the application.
  3. If the ad ids are new it takes 5min - 3,4 hours to display the actual ads. Also make sure you have removed the test device id.
Waqar Khan
  • 42
  • 6
  • first of all i am just asking to uninstall it so that if there is some cache that is not letting it to view ad it could be removed and what the big deal in install and reinstalling a application on your phone. – Waqar Khan Oct 10 '17 at 10:57