S
S
Sp0tted_0wl2014-03-13 22:41:07
Android
Sp0tted_0wl, 2014-03-13 22:41:07

How to create different Android application configurations?

There is an Android application that has a Configuration.java class containing configurations for the dev and production versions of the application. Depending on which version is required, the settings change and the application is built. There was a desire to automate this business and Gradle was chosen as a tool.
The idea is the following: create 2 copies of the Configuration.java file and, depending on the required version of the application, build it with one version of the file or with another. I saw a solution on Ant, but I could not do it on Gradle. The buildTypes section looks like this:

buildTypes {
    dev {
        packageNameSuffix ".dev"
    }
    prod {
        packageNameSuffix ".prod"
    }
}

But I still haven’t figured out how to attach the substitution of Configuration.java files here.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sp0tted_0wl, 2014-03-15
@Sp0tted_0wl

I am answering my own question.
A small manual:
1. Organize the directory structure as follows

src
   main
       java
           com.example.application
               MainActivity.java
       res
       AndroidManifest.xml
   dev
       java
           com.example.application.config
               Configuration.java
   pro
       java
           com.example.application.config
               Configuration.java

2. Add following lines to build.gradle
productFlavors {
        dev {
            ...
        }

        pro {
            ...
        }

3. Command ./gradlew assembleDevDebug (or assembleProDebug)
The output is an assembly that uses the appropriate config file. I hope someone will help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question