Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put specific classes into main DEX file?

We found an issue on Amazon market that IAP doesn't work if it's receivers located not in main DEX file. The question is how to force gradle to put specific classes (receivers) into main DEX file.

EDIT: updated with gradle DEX settings

afterEvaluate {
    tasks.matching {
        it.name.startsWith('dex')
    }.each { dx ->
        if (dx.additionalParameters == null) {
            dx.additionalParameters = []
        }
    dx.additionalParameters += '--multi-dex'
    dx.additionalParameters += "--main-dex-list=class_files.txt" 
    }
}
dexOptions {
    javaMaxHeapSize "4g"
    preDexLibraries = false
}
compile('com.android.support:multidex:1.0.0')
like image 210
Taras Avatar asked May 06 '15 15:05

Taras


1 Answers

With Android Plugin for Gradle, Revision 2.2.0 (Released in September 2016) you can use multiDexKeepFile api

android {
    buildTypes {
        debug {
            ...
            multiDexEnabled true
            multiDexKeepFile file('multidex_keep_file.txt')
        }
    }
}

Where multidex_keep_file.txt is file with single class per line which needs to be explicitly added to the main dex

 com/example/MyClass.class
 com/example/MyClass2.class

You can also use multiDexKeepProguard to keep whole package

-keep class com.example.** { *; }
like image 90
Sergii Pechenizkyi Avatar answered Oct 02 '22 15:10

Sergii Pechenizkyi