我决定尝试apk sliptting来减少我的apk的大小.我将以下内容添加到我的gradle构建文件中
splits { // Configures multiple APKs based on screen density. density { // Configures multiple APKs based on screen density. enable true // Specifies a list of screen densities Gradle should not create multiple APKs for. exclude "ldpi" // Specifies a list of compatible screen size settings for the manifest. compatibleScreens 'small','normal' } }
这成功地为各种密度生成单独的apks.但是,我注意到所有apks都是相同的大小,没有一个比通用apk小.所以,我将一个(app-hdpi-release.apk)加载到apk分析器中,发现它包含所有资源.没有人被剥夺.
因此,所有配置都有效地生成了具有不同文件名的相同apk.我错过了什么吗?是否有任何其他构建选项可能会阻止正在删除的资源?
解决方法
我做了一些打击和试验,最后接受了.在我仅根据屏幕密度进行分割之前.然后我添加了标签$compatibleScreens $,它工作.
这是最后的分割块 –
android { ... splits { density { enable true reset() include "mdpi","hdpi","xhdpi","xxhdpi" // This is the line of code which got it right compatibleScreens 'small','normal','large','xlarge' } } }