请注意: Xavier 答案后编辑的答案
我试图在 Android Studio 中为同一个应用程序项目使用不同的 建立口味。然而,我似乎有一个可怕的时间配置它适当的工作。
步骤:
打开 build.gradle * 并添加以下代码行:
productFlavors {
flavor1 {
packageName 'com.android.studio.test.flavor1'
}
flavor2 {
packageName 'com.android.studio.test.flavor2'
}
}
Created a new Source folder for flavor1; however, I am not sure if I'm doing it the right way. Here's how I did it:
com.foo.test
src
folder, for flavor1, I actually created the individual folders in the explorer, in a way that the structure is src/flavor1/java/com/foo/test/MainActivity.java
. Am I doing something wrong? Or am I missing something? Let me know if you need more info.
*My Project seems to have two build.gradle files. One located on the root of the project folder (\GradleTest), this one is empty. The second one located on the root of a subfolder of \GradleTest, also labeled 'GradleTest' (GradleTest-GradleTest), this is the one that already had code when opened; therefore, that is the one I edited.
** I checked gradle settings and apparently Use auto-import was already enabled. Despite of this, making changes to the build.gradle file doesn't automatically update the build variants. Note: I also tried using Build - Rebuild Project, and/or Build - Make Project, no-go. I still have to close the project, and re-open for changes to take effect.