Android一点 精简google-play-services.jar

本文介绍如何在Eclipse中使用Google Play Services时避免65K方法数限制的问题,通过Gradle构建并精简不必要的类库,确保应用程序能够正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如果在eclipse上使用google-play-services.jar,最新的有5m多,很多的类库我们使用不到,这样在工程上就容易报65k,具体log如下:

[2016-11-21 17:43:13 - Dex Loader] Unable to execute dex: method ID not in [0, 0xffff]: 65536
[2016-11-21 17:43:13 - MHUniSDKExample] Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536

如果使用的Android studio请使用google推荐的 com.android.support:multidex

eclipse的这里:精简 ads、pay、g+用到的库

1、需要用到gradle来构建

2、在build.gradle加上

     

task repack(){
    tasks.create(name: "GDPlayServices", type: Jar) {
        destinationDir = new File("/test")//生成新的jar包的存储位置
        archiveName = "google-play-services-gd.jar" //新jar包的名称
        from(zipTree(new File("/test/google-play-services.jar"))) {
        //用到的package
            include "com/google/android/gms/wearable/**"
            include "com/google/android/gms/common/**"
            include "com/google/android/gms/internal/**"
            include "com/google/android/gms/wallet/**"
            include "com/google/android/gms/plus/**"
            include "com/google/android/gms/auth/**"
            include "com/google/android/gms/identity/intents/**"
            include "com/google/android/gms/signin/internal/**"
            include "com/google/ads/**"
            include "com/google/android/gms/ads/**"
            include "com/google/android/gms/analytics/**"
            include "com/google/android/gms/gcm/**"
        }
    }.execute()
}

//gradlew repack

3、在Terminal中执行

gradlew repack


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值