Pet*_*vka 16 android gradle apk
关于Google Play服务的整体性质以及为什么应将其拆分为更多库,已经写了很多.目前,保持APK较小的解决方法是使用proguard去除未使用的引用.这适用于classes.dex,但不适用于包含的资源.
我获得了大约1 MB的额外未使用资源,并且捆绑的Android Wear应用程序的开销增加了一倍.所以我的APK比需要的大2 MB.
我想知道在Gradle中是否有一些直接的方法可以从生成的APK中排除来自依赖项AAR的一些资源.
似乎Gradle Android插件中的AAPT选项只允许过滤资产.
我正在考虑挂钩一些自定义aapt脚本,在签署APK发布之前使用aapt调用remove for a资源列表.
别人有更简单的解决方案吗?
Pet*_*vka 14
经过一些研究,我发现了以下次优解决方案.我必须手动列出所有不需要的资源(幸运的是模式适用),并确保删除所有引用它们的文件.下面是一个示例,它使我的Wear应用APK从1.5 MB变为300kb并且APK正常工作没有问题.
我必须创建自己的任务stripResources并将其挂钩在标准的Android插件任务之间:mergeReleaseResources和processReleaseResources.
task stripResources << {
println "Custom resource stripping in: $buildDir"
delete fileTree(dir: "$buildDir", include: "**/layout/confirmation_activity_layout.xml")
delete fileTree(dir: "$buildDir", include: "**/layout/watch_card_content.xml")
delete fileTree(dir: "$buildDir", include: "**/common_signin*.png")
delete fileTree(dir: "$buildDir", include: "**/drawable/common_signin*.xml")
delete fileTree(dir: "$buildDir", include: "**/generic_confirmation*.png")
delete fileTree(dir: "$buildDir", include: "**/drawable/confirmation_*.xml")
delete fileTree(dir: "$buildDir", include: "**/drawable/card_background.xml")
delete fileTree(dir: "$buildDir", include: "**/card_frame*.png")
delete fileTree(dir: "$buildDir", include: "**/go_to*.png")
delete fileTree(dir: "$buildDir", include: "**/drawable/go_to_*.xml")
delete fileTree(dir: "$buildDir", include: "**/ic_plusone*.png")
delete fileTree(dir: "$buildDir", include: "**/powered_by_google*.png")
// if you only have English you can teh following to filter out some GPS texts wich also take few hundreds of kb
// delete fileTree(dir: "$buildDir", include: "**/values-*/values.xml")
}
tasks.whenTaskAdded { task ->
if (task.name == 'processReleaseManifest') {
task.dependsOn stripResources
}
}
Run Code Online (Sandbox Code Playgroud)
您可以为常规Android APK执行类似的任务.
| 归档时间: |
|
| 查看次数: |
904 次 |
| 最近记录: |