-2

here is my app build gradle code

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.2"

defaultConfig {
    applicationId "com.example.personal.numbermania"
    minSdkVersion 10
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}

dexOptions {
    incremental true
    javaMaxHeapSize "4g" //Here stablished how many cores you want to use your android studi 4g = 4 cores
}


buildTypes {
    debug
            {
                debuggable true
            }
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.google.firebase:firebase-ads:9.6.1'
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.android.gms:play-services:9.6.1'

}

apply plugin: 'com.google.gms.google-services'

here is my project build gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.1.3'
    classpath 'com.google.gms:google-services:3.0.0'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}

allprojects {
repositories {
    jcenter()
}

}

task clean(type: Delete) {
delete rootProject.buildDir

}

Here is my error when running error

Lakshmi
  • 1,791
  • 3
  • 9
  • 10

2 Answers2

0

To initialize before call AdView

    MobileAds.initialize(getApplicationContext(), "ca-app-pub-3940256099942544~3347511713");
    //replace your ID
    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

More details refer Here

sasikumar
  • 12,540
  • 3
  • 28
  • 48
0

After you compile your code, you have .class files for every class in your program. These files include bytecode that Java uses to interpret and run your program. The JVM tried to find a .class file however, it could not find it causing a runtime error, NoClassDefError.

Adding the following code to build.gradle file fixes this issue:

dexOptions {
   incremental true
   javaMaxHeapSize "4g" 
}

Other things to try in order to debug/solve this issue

Method 1:

  • Update Google Play Services to Revision 30 from Android SDK Manager > Extras.
  • Add com.android.support.multidex:1.0.1 to your dependencies or remove multiDexEnabled true if it is not required.
  • Add attribute - android:name="android.support.multidex.MultiDexApplication" to the application tag in AndroidManifest

Note: If your AndroidManifest already has a custom application class defined, extend MultiDexApplication instead of Application.

Method 2:

Another way of updating Application class:

public class App extends Application {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        ...
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

Method 3:

If method 1 and method 2 are unsuccessful, try downgrading your Google Play Services dependency down to 8.4.0

Prad
  • 515
  • 7
  • 15
  • what is firebase options? – Lakshmi Oct 24 '16 at 11:30
  • public class App extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } } – Lakshmi Oct 24 '16 at 13:46
  • give me ur mail id .Let's discuss in mail – Lakshmi Oct 24 '16 at 13:47
  • You put it with your `MainActivity` – Prad Oct 24 '16 at 13:57
  • is it inside on create method? – Lakshmi Oct 24 '16 at 14:11
  • I still have the error.Give me ur mail id.Lets discuss in mail – Lakshmi Oct 24 '16 at 14:18
  • No, it is its own method. I've modified my answer to help you a little more. Also, if my answer works for you, please consider choosing it as the accepted answer. If it doesn't work, could you modify your question with more of the relevant files. – Prad Oct 24 '16 at 14:18
  • both the solutions give error even downgrading to 8.4.0 didn't work – Lakshmi Oct 24 '16 at 14:23
  • I have tried new method that u have posted.Even that doesn't work. – Lakshmi Oct 24 '16 at 14:31
  • I'm not exactly sure what else the problem could be. If I learn something, I'll update my answer. Also, I don't share my mail with others on StackOverflow. – Prad Oct 24 '16 at 15:09
  • my mail id is sribhanu93@gmail.com.u can mail me to this mail id.I will make sure that it is confidential – Lakshmi Oct 24 '16 at 15:11
  • Did you do something different than what I recommended? – Prad Oct 25 '16 at 13:21
  • dexOptions { incremental true javaMaxHeapSize "4g" //Here stablished how many cores you want to use your android studi 4g = 4 cores } – Lakshmi Oct 25 '16 at 14:30
  • I've updated my answer with the correct solution for anyone in the future having this issue. Glad you were able to fix the problem. Thanks – Prad Oct 25 '16 at 15:11