简体   繁体   中英

Different files and gradle android studio

I have a project where I need to generate two versions. One pointing to development servers and the other to production servers. The previous developers created a configuration file .properties there they have the endpoints set up. My questions is. How can I modify or generate the two versions with Android Studio. I know about the flavors and build types, but is there a way to keep lets say two .properties files and the compiler use them in each case.

Best regards

Pedro.

You want to use Gradle flavors. In a nutshell, it allows you to include different resources in different build-time variations (flavors).

In your build.gradle ,

android {
  productFlavors {
    flavor1 {
    }
    flavor2 {
    }
  }
}

This will create two different APKS, one for each flavor. Now, in your src tree,

src\
  main\
  flavor1\
  flavor2\

Now for example if your .properties file was stored as an asset, you'd have src/flavor1/assets/foo.properties and src/flavor2/assets/foo.properties .

You can also include different source files, and Android manifests. The directory structure under the flavor folder is the same as you'd find in main and can contain all of the same resources.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM