Search code examples
androidandroid-multidexamazon-fire-tv

The app exceeded 65k reference limit. Please enable multidexing your app or use ProGuard to reduce methods and resubmit the app on amazon store


I am uploading my Fire TV application on Amazon app store. I got error of multidex library.

The app exceeded 65k reference limit. Please enable multidexing your app or use ProGuard to reduce methods and resubmit the app.

Below is my app gradle file

apply plugin: 'com.android.application'
android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 26
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        disable 'MissingTranslation'
    }
    dexOptions {
        javaMaxHeapSize = "4g"
        preDexLibraries = false
    }
}


dependencies {
    // Glide image library
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.android.support:support-v4:26.0.0'
    compile 'com.android.support:appcompat-v7:26.0.0'
    compile 'com.google.android.gms:play-services:+'
    compile 'com.google.android.gms:play-services-analytics:10.2.4'
    compile 'com.android.support:multidex:1.0.2'
    compile 'com.android.volley:volley:1.0.0'
    compile project(path: ':library')
    compile project(path: ':ffmpeg')
    compile project(path: ':okhttp')
    compile project(path: ':opus')
    compile project(path: ':flac')
    compile project(path: ':playbacktests')
    compile project(path: ':testutils')
    compile project(path: ':vp9')
    compile files('libs/WebtrendsAndroidClientLib.jar')
}

Below is AndroidManifest File

<application
    android:name=".controller.app.MyApp"
    android:allowBackup="true"
    android:banner="@drawable/tv_launcher"
    android:hardwareAccelerated="false"
    android:icon="@drawable/app_logo"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Black.NoTitleBar">

Below is Application class

public class MyApp extends Application {
    @Overrideprotected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

What is going wrong with my code regarding multidex enable that amazon store reject my apk for uploading with multidex error? Please give me solution


Solution

  • chances are you probably don't need to enable multidex. compiling all of play-services is very ill advised because that is what is most likely causing you to go over the limit in the first place. play-services compiles ALL the play-services libraries as opposed to just picking the ones you need

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

    without looking at the rest of your project it is hard to tell what other dependencies you need from google play services but you should definitely steer clear of compiling all them since that is probably 99% reason you're running over 64k. Another problem is you have play-services version = '+' and analytics version = 10.2.4 when the latest is 11.6.0 so those versions don't even match. if you have play-services: you don't need play-services-analytics: because of what I mentioned above.

    https://developers.google.com/android/guides/setup

    check out the list of sub-libraries on their site and only use the sub-libraries you need.

    also since your min sdk is 21, you don't need to compile the multidex library, it is included, "if your minSdkVersion is 21 or higher, you do not need the multidex support library."

    compile 'com.android.support:multidex:1.0.2'
    

    https://developer.android.com/studio/build/multidex.html

    so you already set multiDexEnabled true in your defaultConfig

    under the title "Configure your app for multidex" in the documentation you can setup multidex for your project. try extending MultiDexApplication

        public class MyApplication extends MultiDexApplication { ... }