android - play-services-base 和 support-v4 双方法计数

标签 android gradle google-play-services android-support-library dex

根据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'
...
}
...

Android 插件的结果:
enter image description here

最佳答案

方法计数并不是严格意义上的累加。 64k方法限制是对dex文件中method_id_item列表中条目数量的限制。这是在 dex 文件中的任何位置引用的唯一方法 ID 的列表(类名 + 方法名 + 参数 + 返回类型)。因此,从两个库引用的任何方法都将在最终的 dex 文件中进行重复数据删除,并且两个库贡献的总方法数将略小于各个库的 15k + 9k。

关于android - play-services-base 和 support-v4 双方法计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39266035/

相关文章:

javascript - 如何从电池优化权限弹出窗口获取授予状态

gradle - 在gradle + groovy项目中自动创建的Java源文件夹

android - React Native Gradle assembleDebug 需要一个小时

android - 由 com.google.android.gms.DynamiteModules 引起的 ANR

android - 额外的不会通过 Intent

android - 有没有办法将 "hidden"数据添加到 GCM(android 推送)通知?

android - 从 gradle 运行 HelloAndroid?

java - BaseGameUtils编译时,Vungle初始化崩溃

android - Plus.PeopleApi.getCurrentPerson 在 Play 服务 8.4 中已弃用。如何使用 GoogleSignInApi 获取用户的名字、姓氏和性别?

android - 如何在 Android 上找到传递给 Delphi 应用程序的文件?