按密度分割的APK仍包含所有资源 [英] APK split by density still contains all resources

查看:104
本文介绍了按密度分割的APK仍包含所有资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定尝试使用apk来减少我的apk的大小。我将以下内容添加到我的gradle构建文件中

  splits {

//根据屏幕密度。
密度{

//根据屏幕密度配置多个APK。
启用true

//指定屏幕密度列表Gradle不应为其创建多个APK。
排除ldpi

//指定清单的兼容屏幕大小设置列表。
compatibleScreens'small','normal'
}
}

这成功地为各种密度生成单独的证书。但是,我注意到所有的apks都是相同的大小,没有一个比通用apk小。所以,我将一个(app-hdpi-release.apk)加载到apk分析器中,发现它包含了所有资源。没有人被剥夺。

因此,所有的配置都是用不同的文件名生成相同的apk。我错过了什么吗?有没有其他的构建选项可能会阻止资源被删除?

解决方案

我做了一些命中和试用,最后它公认。在我仅以屏幕密度为基础分裂之前。然后,我添加了标签$ compatibleScreens $,它工作正常。



这是最后的拆分块 -



<$ p $ (










$ b $
包含mdpi,hdpi,xhdpi,xxhdpi

//这就是正确的代码行
compatibleScreens'small','正常','大','x大'
}
}
}


I decided to try apk sliptting to reduce the size of my apk. I added the following to my gradle build file

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'
    }
}

This successfully generates separate apks for the various densities. However, I noticed that all of the apks were the same size, none of them were smaller than the universal apk. So, I loaded one (app-hdpi-release.apk) into the apk analyzer and found that it contained all resources. None were stripped out.

So effectively all the config did was to generate the same apk with different filenames. Am I missing something? Are there any other build options that could potentially be blocking the resources being removed?

解决方案

I did some hit and trial and finally it accepted. Before I was splitting on the basis of screen densities ONLY. Then I added the tag $compatibleScreens$ and it worked.

Here is the final split block-

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'
    }
  }
}

这篇关于按密度分割的APK仍包含所有资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆