如何将特定的类放入主DEX文件

如何将特定的类放入主DEX文件

本文介绍了如何将特定的类放入主DEX文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在亚马逊市场上发现了一个问题,即如果接收方不在主要 DEX 文件。
问题是如何强制 gradle 将特定类(接收器)放入主 DEX 文件中。 / p>

编辑:用gradle DEX设置更新

  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 {
javaMaxHeapSize4g
preDexLibraries = false

compile('com.android.support:multidex:1.0.0')


multiDexKeepFile api



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

其中 multidex_keep_file.txt 是每行只有一个类的文件,需要显式地添加到主dex中。

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

您也可以使用 multiDexKeepProguard 保留整个包

  -keep class com.example。** {*; } 


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')
解决方案

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.** { *; }

这篇关于如何将特定的类放入主DEX文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 05:30