Avoiding the Dalvik 65K Method Limit

Android APKs have a limit of 65K methods for a single DEX file. This limit can easily be reached when including the Google Play Services SDK required by the TUNE Android SDK, as the Google Play Services SDK alone holds over 20K methods.

There are several ways to reduce the amount of methods added to your app. When working with third-party libraries, you can include only the methods your app actually uses during the build process. The TUNE SDK only requires the Ads library in the Google Play Services SDK, in order to access the Google Advertising ID.

ProGuard

We recommend using ProGuard to strip any unused methods during compilation. To set up ProGuard for Google Play Services, add to your <project_directory>/proguard-project.txt file:

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}
 
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}
 
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}
 
-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

Please note that ProGuard will apply only for release builds.

Reference:
http://developer.android.com/google/play-services/setup.html#Proguard

Selective Gradle Compilation

For a Gradle build, you may also selectively include only the required Ads API from the SDK, starting from Google Play Services version 6.5+.

In your build.gradle file, include only the “play-services-ads” library as a dependency:

compile 'com.google.android.gms:play-services-ads:7.5.0'

instead of

compile 'com.google.android.gms:play-services:7.5.0'

Reference:
http://developer.android.com/google/play-services/setup.html#Setup

Multidex

You may consider configuring your app as a multidex build to circumvent the 65K limit if you are still above the limit:
https://developer.android.com/tools/building/multidex.html

No Comments

Leave a reply