使用 Android Studio 中的一个项目构建创建多个 apk 文件 [英] Create multiple apk files with one project build in Android Studio
问题描述
我的 Android 项目中有两种风格,一种用于测试服务器,一种用于生产.我将 URL 存储在字符串资源中,因此我可以根据我选择进行编译的风格访问正确的 URL.通常我需要在一天内为两个服务器创建多个 apk 文件.
I have two flavors in my Android project, one works with test server and one with production. I store the URL inside a string resource, so I may access the correct URL based on a flavor that I choose for compilation. Usually I need to create multiple apk files during a day, each time for both servers.
有没有办法在每次运行我的项目或从 Build 菜单构建 apk 时创建两个 apk 文件?
Is there a way to create two apk files each time I run my project or build an apk from Build menu?
推荐答案
如果你有这样的事情:
android {
productFlavors {
dev {
applicationId "your.com.android.devel"
buildConfigField 'String', 'HOST', '"http://192.168.1.78"'
}
prod {
applicationId "your.com.android"
buildConfigField 'String', 'HOST', '"http://yourserver.com"'
}
}
}
你只需要在 Gradle 项目中运行 assemble
You only have to run assemble in Gradle projects
你可以找到所有不同的 apk build/outputs/apk
And you can find all the different apks build/outputs/apk
希望这次我会更有帮助
这篇关于使用 Android Studio 中的一个项目构建创建多个 apk 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!