Play Service 6.5。+粒度依赖关系无法正常工作

时间:2015-04-01 16:20:20

标签: android android-studio gradle google-play-services dependency-management

UPDATE:根据请求,来自build.gradle的整个依赖项声明,jar列表以及所包含的库项目的依赖项列在问题的底部。


我正在开发一个使用Google Play服务(版本7.0.0)的位置,gcm,广告和标识组件的项目。

我已经在app模块的build.gradle中定义了它们:

compile 'com.google.android.gms:play-services-location:7.0.0'
compile 'com.google.android.gms:play-services-ads:7.0.0'
compile 'com.google.android.gms:play-services-identity:7.0.0'
compile 'com.google.android.gms:play-services-gcm:7.0.0

注意:不知道它是否相关(我不希望它),但该项目还包括两个额外的库模块,其中一个声明了上面的子集作为依赖:

compile 'com.google.android.gms:play-services-location:7.0.0'
compile 'com.google.android.gms:play-services-ads:7.0.0'
compile 'com.google.android.gms:play-services-identity:7.0.0'

但是,在尝试构建应用程序之后,由于超过64k方法计数限制,dexing失败了。我对此有点怀疑,因为在Google的优秀人员引入粒度依赖管理之前,我使用了another, more crude approach, by manually stripping away packages from the play services jar in a gradle build task。这工作正常,64k方法限制没有超越。

所以现在,我不情愿地将multi-dex引入到项目中,最终能够构建一个.apk,并使用dex-method-counts command line tool来查看方法计数,这引起了我的注意在a post by Jake Wharton concerning the unwieldiness of the Play Services monolith

结果如下:

        google: 18687
            ads: 127
                mediation: 96
                    admob: 23
                    customevent: 41
            android: 11873
                gms: 11873
                    actions: 4
                    ads: 387
                        doubleclick: 84
                        identifier: 22
                        mediation: 75
                            admob: 2
                            customevent: 48
                        purchase: 16
                        search: 81
                    analytics: 656
                        ecommerce: 34
                    auth: 78
                    common: 1611
                        api: 409
                        data: 141
                        images: 100
                        internal: 580
                            safeparcel: 76
                    dynamic: 213
                    gcm: 35
                    identity: 86
                        intents: 75
                            model: 41
                    internal: 4914
                    location: 516
                        places: 232
                            ui: 7
                    maps: 2395
                        internal: 822
                        model: 1020
                            internal: 505
                    security: 12
                    tagmanager: 955
            common: 5798
                annotations: 3
                base: 558
                    internal: 11
                collect: 4195
                io: 299
                net: 72
                primitives: 383
                util: 288
                    concurrent: 288
            gson: 889
                annotations: 5
                internal: 485
                    bind: 284
                reflect: 18
                stream: 102

TL; DR Play服务被列为拥有超过18k的方法,并且似乎还包括一些我从未在build.gradle中定义为依赖项的组件(例如地图)。

那么,我使用Jake Wharton在上面引用的文章中的方法,直接从android-sdk-linux/extras/google/m2repository/com/google/android/gms/play-services-<component_name>中逐个使用我使用的组件。

结果如下:

Base:

Read in 3592 method IDs.
<root>: 3592
    : 6
    android: 420
        accounts: 5
        app: 62
        content: 71
            pm: 12
            res: 9
        database: 21
        graphics: 42
            drawable: 21
        net: 11
        os: 102
        support: 56
            v4: 56
                app: 45
                content: 4
                util: 7
        text: 1
        util: 22
        view: 4
        widget: 23
    com: 2831
        google: 2831
            android: 2831
                gms: 2831
                    actions: 4
                    auth: 78
                    common: 1611
                        api: 409
                        data: 141
                        images: 100
                        internal: 580
                            safeparcel: 76
                    dynamic: 213
                    internal: 913
                    security: 12
    java: 324
        io: 25
        lang: 143
            ref: 2
            reflect: 13
        math: 2
        nio: 17
        util: 137
            concurrent: 26
                atomic: 4
                locks: 7
            regex: 6
    org: 11
        json: 11
Overall method count: 3592

---

Location:

Read in 1554 method IDs.
<root>: 1554
    android: 65
        app: 1
        content: 13
        location: 3
        net: 1
        os: 41
        text: 1
        util: 5
    com: 1417
        google: 1417
            android: 1417
                gms: 1417
                    common: 75
                        api: 13
                        data: 8
                        internal: 53
                            safeparcel: 36
                    internal: 833
                    location: 505
                        places: 232
                            ui: 7
                    maps: 4
                        model: 4
    java: 72
        lang: 31
        util: 41
            concurrent: 1
Overall method count: 1554

---

GCM:

Read in 72 method IDs.
<root>: 72
    android: 27
        app: 2
        content: 16
            pm: 1
        os: 8
        util: 1
    com: 24
        google: 24
            android: 24
                gms: 24
                    gcm: 24
    java: 21
        io: 1
        lang: 12
        util: 8
            concurrent: 5
                atomic: 2
Overall method count: 72

---

Ads:

Read in 3878 method IDs.
<root>: 3878
    android: 471
        app: 50
        content: 75
            pm: 5
            res: 7
        database: 13
            sqlite: 7
        graphics: 12
            drawable: 1
        location: 4
        media: 5
        net: 25
        os: 67
        provider: 1
        telephony: 3
        text: 2
        util: 16
        view: 67
        webkit: 64
        widget: 67
    com: 3059
        google: 3059
            ads: 127
                mediation: 96
                    admob: 23
                    customevent: 41
            android: 2932
                gms: 2932
                    ads: 353
                        doubleclick: 84
                        mediation: 75
                            admob: 2
                            customevent: 48
                        purchase: 16
                        search: 81
                    analytics: 2
                    common: 39
                        internal: 37
                            safeparcel: 27
                    dynamic: 5
                    internal: 2533
    java: 318
        io: 16
        lang: 126
            ref: 2
            reflect: 3
        math: 7
        net: 23
        security: 11
            spec: 1
        text: 2
        util: 133
            concurrent: 28
                atomic: 7
    org: 30
        json: 30
Overall method count: 3878

---

Identity

Read in 179 method IDs.
<root>: 179
    android: 34
        accounts: 1
        app: 2
        content: 5
        os: 23
        text: 1
        util: 2
    com: 135
        google: 135
            android: 135
                gms: 135
                    common: 28
                        api: 4
                        internal: 21
                            safeparcel: 15
                    identity: 75
                        intents: 75
                            model: 41
                    internal: 32
    java: 10
        lang: 6
        util: 4
Overall method count: 179

TOTAL: 9275

TL; DR 我使用的所有组件的总方法计数实际上是9275,不到问题开始时使用gradle构建生成的.apk最终的一半!

尝试在没有multi-dex支持的情况下构建.apk失败,再次超越64k方法限制。

我真的不知道这里发生了什么,并希望得到一些帮助。 Multi-dex很好,但是8k方法对于我的项目来说是一个相当大的缓冲区,如果粒度依赖项按预期工作,我将不会在很长一段时间内引入multi-dex。 / p>

另外,请不要建议将proguard作为解决方案。它充其量只是一个创可贴,如果正确处理依赖关系,则不需要调试版本。


所有依赖

来自应用程序本身:

dependencies {
    compile 'com.android.support:multidex:1.0.0'
    compile project(':external_libs:GuJEMSSDK-Android:GuJEMSSDK-Android-library')
    compile project(':external_libs:facebook-android-sdk:facebook')
    compile 'com.android.support:support-v4:22.0.0'
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.google.android.gms:play-services-location:7.0.0'
    compile 'com.google.android.gms:play-services-ads:7.0.0'
    compile 'com.google.android.gms:play-services-identity:7.0.0'
    compile 'com.google.android.gms:play-services-gcm:7.0.0'
    compile 'com.viewpagerindicator:library:2.4.1@aar'
    compile 'uk.co.chrisjenx:calligraphy:1.1.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.j256.ormlite:ormlite-core:4.48'
    compile 'com.j256.ormlite:ormlite-android:4.48'
    compile 'com.github.bumptech.glide:glide:3.5.2'
    androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.2.1'
}

这里列出了JAR的价值:

adjust-android-4.0.2.jar
amazon-in-app-purchasing-1.0.3.jar
android-support-v7-recyclerview.jar
DistimoSDK.jar
eventbus-2.2.1.jar
FlurryAnalytics_3.3.2.jar
httpmime-4.1.2.jar
MobileAppTracker-3.0.jar
plasma-1.95.0.jar
SKMaps.jar
socialauth-4.3.jar
socialauth-android-3.0.jar

以下是两个包含的库项目的build.gradle脚本的依赖项:

compile files('libs/videoadsdk.jar')
compile files('libs/openudidandroid.jar')
compile 'com.google.android.gms:play-services-location:7.0.0'
compile 'com.google.android.gms:play-services-ads:7.0.0'
compile 'com.google.android.gms:play-services-identity:7.0.0'

dependencies {
    compile 'com.android.support:support-v4:22.0.0'
}

第二个是Facebook,并且在其libs目录中有Bolts.jar。

希望这有帮助!

0 个答案:

没有答案