11

My app is running well on Lollipop devices but it keep crashing on prior to version Lollipop. I have simply implemented a banner add in my application with the following code through google documention

    // Request for Ads
           AdRequest adRequest = new AdRequest.Builder()

                  // Add a test device to show Test Ads
                 .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                 .build();

         // Load ads into Banner Ads
         mAdView.loadAd(adRequest);

using

    compileSdkVersion 23
    buildToolsVersion "23.0.1"

manifest

  <meta-data
             android:name="com.google.android.gms.version"
             android:value="@integer/google_play_services_version" />

         <activity
             android:name="com.google.android.gms.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden
   |orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

Error

 E/AndroidRuntime: FATAL EXCEPTION: main
 E/AndroidRuntime: Process: com.app.aggro, PID: 13257
 E/AndroidRuntime: java.lang.VerifyError: 
  com/google/android/gms/measurement/internal/zzv
 E/AndroidRuntime: at   
 com.google.android.gms.measurement.AppMeasurementContentProvider
.onCreate(Unknown Source)
E/AndroidRuntime:     at  
android.content.ContentProvider.attachInfo(ContentProvider.java:1656)
 E/AndroidRuntime:     at  
android.content.ContentProvider.attachInfo(ContentProvider.java:1627)
 E/AndroidRuntime:     at  
android.app.ActivityThread.installProvider(ActivityThread.java:5015)
E/AndroidRuntime:     at  
android.app.ActivityThread.installContentProviders
(ActivityThread.java:4589)
 E/AndroidRuntime:     at   
 android.app.ActivityThread.handleBindApplication
 (ActivityThread.java:4522)
E/AndroidRuntime:     at  
android.app.ActivityThread.access$1500(ActivityThread.java:151)
E/AndroidRuntime:     at  
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1381)
E/AndroidRuntime:     at 
android.os.Handler.dispatchMessage(Handler.java:110)
E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:193)
  E/AndroidRuntime:     at  
android.app.ActivityThread.main(ActivityThread.java:5299)
E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native  
Method)
E/AndroidRuntime:     at  
java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime:     at   
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:825)
 E/AndroidRuntime:     at   
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
E/AndroidRuntime:     at dalvik.system.NativeStart.main
(Native Method)

My Gradle file is

 apply plugin: 'com.android.application'

 buildscript {
     repositories {
         maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
         classpath 'io.fabric.tools:gradle:1.+'
     }
 }
 repositories {
     mavenCentral()
     maven { url   
 "https://oss.sonatype.org/content/repositories/snapshots"}
        maven { url 'https://maven.fabric.io/public' }
        maven { url   
     "https://oss.sonatype.org/content/repositories/snapshots/" }
     maven { url 'https://dl.bintray.com/drummer-aidan/maven' }
 }
android {
     compileSdkVersion 23
     buildToolsVersion "23.0.1"

    defaultConfig {
         applicationId "com.app.aggro"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
     }
     buildTypes {
         release {
             minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-
android.txt'), 'proguard-rules.pro'
        }
    }


    dexOptions{
        incremental true
        javaMaxHeapSize "4g"
     }
    defaultConfig {
        multiDexEnabled true
    }
    packagingOptions {
         exclude 'META-INF/DEPENDENCIES'
         exclude 'META-INF/NOTICE'
         exclude 'META-INF/LICENSE'
         exclude 'META-INF/LICENSE.txt'
         exclude 'META-INF/NOTICE.txt'
     }
  }

 dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile('com.mikepenz:materialdrawer:3.0.9@aar') {
        transitive = true
     }
     compile('com.github.florent37:materialviewpager:1.1.0@aar') {
         transitive = true
    }


    compile('com.crashlytics.sdk.android:crashlytics:2.4.0@aar') {
        transitive = true;
     }
    compile 'com.google.android.gms:play-services:8.1.0'
     compile 'com.mcxiaoke.volley:library:1.0.+'
     compile 'com.google.code.gson:gson:2.3.1'
      compile 'com.marshalchen.ultimaterecyclerview:library:0.3.11'
     compile 'com.android.support:recyclerview-v7:22.2.0'
     compile 'com.android.support:cardview-v7:23.0.1'
     compile 'com.jpardogo.googleprogressbar:library:1.2.0'
      compile 'com.quinny898.library.persistentsearch:library:1.0.0-  
 SNAPSHOT'
     compile project(':storage')
     compile 'com.getbase:floatingactionbutton:1.10.0'
     compile 'com.parse.bolts:bolts-android:1.+'
      compile files('libs/activeandroid-3.1-beta.jar')
      compile 'com.android.support:design:23.0.1'
      compile 'it.neokree:MaterialTabs:0.11'
      compile 'com.miguelcatalan:materialsearchview:1.2.0'
  }

Please help me out to get out from this problem.

Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
Nirmal
  • 939
  • 10
  • 24

4 Answers4

34

After expanding more than a hour on problem, I found that I have to do some modification in MyApplication Class like this:

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        // register with Active Android
        ActiveAndroid.initialize(this);
    }

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

I have overriden the attachbaseContext method and all works fine now.

Mahendran Sakkarai
  • 8,381
  • 6
  • 44
  • 66
Nirmal
  • 939
  • 10
  • 24
  • where is MyApplication class in our Android Studio project? – Dalvinder Singh Sep 22 '16 at 10:33
  • You need to create one . Just create a simple java class and extends it from Application class as i did you can see in my answer and override the attachBaseContext method.Also include dependency in your app build gradle file compile 'com.android.support:multidex:1.0.1' .And in manifest application tag include the class like this android:name=". Your class name" – Nirmal Sep 22 '16 at 10:53
5

+) Building Apps with Over 65K Method will cause this Error.

+) When your application and the libraries it references reach a certain size ( DEX file of your application can have total number of methods upto 65,536 including Android framework methods, library methods, and methods in your own code), you encounter build errors that indicate your app has reached a limit of the Android app build architecture.

+) To resolve it, include Multidex Configuration in your build.gradle like the highlighted one in picture, along with this override the attachBaseContext(Context base) method in your Application class with the below content.

public class YourParentApplication extends Application {

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

Add this in you Androidmanifest.xml:

<application
    android:name=".YourParentApplication"
    android:allowBackup="true"
    android:icon="@drawable/radiius_logo"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:theme="@style/MyMaterialTheme">

For more information about Multidex refer these site: http://developer.android.com/tools/building/multidex.html

How to enable multidexing with the new Android Multidex support library

enter image description here

Community
  • 1
  • 1
anand krish
  • 4,281
  • 4
  • 44
  • 47
0

You should lower the API in your AndroidManifest.xml Lollipop is API 21.

Check this out: API Levels Example:

   defaultConfig {
        applicationId "com.package.name"
        minSdkVersion 11
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
Geert Berkers
  • 653
  • 7
  • 19
0

reduce your minSdkversion to that version you want to give support

in gradle file of your project

As below

minSdkVersion 10

Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142