[英]Android build variants multiple applications
I have one Android project contains 2 modules:我有一个 Android 项目包含 2 个模块:
I've done it this way because I need to use the core functionality in the non-Android environment, as a standalone jar.我这样做是因为我需要在非Android环境中使用核心功能,作为独立的jar。
Now, I need to create another application that needs to use the core functionality + Java packages inside the app module (I can't get them out of there).现在,我需要在 app 模块中创建另一个需要使用核心功能 + Java 包的应用程序(我无法将它们从那里取出)。
So I thought using build variants can help me.所以我认为使用构建变体可以帮助我。 I created 2 build variants, one for the old application and second to the new application.
我创建了 2 个构建变体,一个用于旧应用程序,另一个用于新应用程序。
Everything works fine, but I can see that all my resources in the main directory are being packaged into the apk of the new application, even though the second application requires a small number of resources.一切正常,但我可以看到我在主目录中的所有资源都被打包到新应用程序的 apk 中,即使第二个应用程序需要少量资源。
I've searched about how to exclude unused resources like this , but in my case, I need to remove only unused resources, not entire folders.我已经搜索过如何像这样排除未使用的资源,但就我而言,我只需要删除未使用的资源,而不是整个文件夹。
I think you should use the shrink resources
functionality which removes unused resources during compilation.我认为您应该使用
shrink resources
功能,该功能会在编译期间删除未使用的资源。 You don't need to manually point to directories or files to exclude them - gradle will do that for you:)您无需手动指向目录或文件来排除它们 - gradle 将为您做到这一点:)
https://developer.android.com/studio/build/shrink-code.html#shrink-resources https://developer.android.com/studio/build/shrink-code.html#shrink-resources
and in the code:并在代码中:
buildTypes {
newApp {
minifyEnabled true
shrinkResources true
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.