A lot has been written about the monolithic nature of the Google Play Services and why it should be split into more libraries. For now the workaround to keep your APK small is t
After some research I found the following sub-optimal solution. I had to list all the not needed resources manually (luckily patterns are applicable) and make sure also to delete all files where they are referenced. Below is an example which makes my Wear app APK from 1.5 MB into 300kb and the APK is working normally without issues.
I had to create my own task stripResources
and hook it between standard Android plug-in tasks: mergeReleaseResources
and 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
}
}
You can do a similar task for regular Android APK.