0

我正在使用带有 Google Play Services 7.5、Android 21 和 Support v4 库的 proguard 编译一个项目。如果我用 android studio 编译它,我的方法计数比用 eclipse 编译它的要高。我在两个程序生成的两个 apk 中使用了一个名为 dex-method-count 的程序,我发现这就是原因:

AndroidStudio+gradle:

    support: 5416
        v4: 2755
            app: 594
            content: 33
            graphics: 96
                drawable: 96
            internal: 74
                view: 74
            media: 123
                session: 60
            os: 13
            text: 17
            util: 166
            view: 1024
                accessibility: 204
            widget: 615
        v7: 2661
            app: 232
            appcompat: 1
            internal: 1757
                app: 77
                text: 3
                transition: 1
                view: 628
                    menu: 536
                widget: 1047
            view: 24
            widget: 647

日食+蚂蚁:

    support: 2073
        v4: 2073
            app: 549
            content: 21
            media: 123
                session: 60
            os: 11
            util: 157
            view: 757
                accessibility: 204
            widget: 455

正如您在第一个选项中看到的那样,它添加了许多来自支持 v7 的方法,为什么?如何避免这种情况?

谢谢

PD:我的库和应用程序的构建 gradle 文件:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 'Google Inc.:Google APIs:22'
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 10
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        }
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.google.android.gms:play-services:7.5.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

应用程序:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'Google Inc.:Google APIs:22'
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.launcher"
        minSdkVersion 10
        targetSdkVersion 10
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        }
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        }
    }
}

dependencies {
    compile project(':caponateLibrary')
    compile 'com.google.android.gms:play-services:7.5.0'
}
4

1 回答 1

1

com.google.android.gms:play-services依赖于com.google.android:wearablecom.google.android:play-services-cast。其中每一个都依赖于v7支持库(分别为recyclerview-v7和)。mediarouter-v7

除非您使用 Play Services SDK 中的几乎所有内容,否则使用更细粒度的依赖项将获得更好的服务(请参阅本页上的“选择性地将 API 编译到可执行文件中” )。这不仅会摆脱一堆播放服务的臃肿,而且可能会摆脱您的v7方法,具体取决于您使用的播放服务的哪些位。

顺便说一句,compileSdkVersion 'Google Inc.:Google APIs:22'这是毫无意义的,除非您仍在使用 Maps V1,在现阶段这将是相当令人惊讶的。compileSdkVersion 22会是更好的选择。

于 2015-08-19T15:26:47.763 回答