Android Studio build flavors - How to have same source files in diverse flavors

后端 未结 3 1080
后悔当初
后悔当初 2020-12-30 02:51

I need to create a demo flavor in android studio for an app. In my app level gradle file i have created another flavor called demo and the default flavor of full of course.

3条回答
  •  别那么骄傲
    2020-12-30 03:22

    I was able to override classes but the key was not to include the class in my main folder.

    So the fullDebug (i.e. main folder) build variant will never get run. Always run a flavor and not the main folder. The main folder will just be used to keep common things in it.

    In my case I had a demo for USA and another country (demo and demo_us)and I needed two flavors. I'll always build for either of the two and won't build main.

    enter image description here

    From the image you can see I made all my package names to be the same: like com.example.******.myapplication. Since they all have the same package name in the MainActivity you just import Hello.java with that package name and it will pick the right variant at build time.

    For resources it looks like it's different and it will override naturally but java class files have to do this way.

提交回复
热议问题