根据methods.com play-service-base
共有 15k 个方法。不过,我已经在我的 build.gradle
中包含了 Android support-v4
(~9k 方法)。是否有办法确保我的应用程序中的总方法计数为 15k,而不是 24k = 15k + 9k?
我的构建等级:
...
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
androidTestCompile('com.android.support.test:runner:0.5') {}
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
exclude group: 'com.android.support', module: 'design'
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
exclude module: 'support-annotations'
}
androidTestCompile 'com.android.support:support-annotations:23.4.0'
compile('com.crashlytics.sdk.android:crashlytics:2.6.1@aar') {
transitive = true;
}
compile('com.android.support:appcompat-v7:23.4.0') {
force true
}
compile('com.android.support:support-v4:23.4.0') {
force = true;
}
compile('com.android.support:recyclerview-v7:23.4.0') {
force = true;
}
compile('com.android.support:cardview-v7:23.4.0') {
force = true;
}
compile('com.android.support:design:23.4.0') {
force = true;
}
apt 'com.jakewharton:butterknife-compiler:8.2.1'
compile 'com.android.support:percent:23.4.0'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.google.android.gms:play-services-base:9.2.0'
compile 'com.google.android.gms:play-services-location:9.2.0'
...
}
...
最佳答案
方法计数并不是严格意义上的累加。 64k方法限制是对dex文件中method_id_item列表中条目数量的限制。这是在 dex 文件中的任何位置引用的唯一方法 ID 的列表(类名 + 方法名 + 参数 + 返回类型)。因此,从两个库引用的任何方法都将在最终的 dex 文件中进行重复数据删除,并且两个库贡献的总方法数将略小于各个库的 15k + 9k。
关于android - play-services-base 和 support-v4 双方法计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39266035/