简体   繁体   中英

development and production version of one app

I develop an app with Android Studio and I want to create different versions of the app.

  1. Development version should always use the test website www.aaaaaaaaa.com
  2. Production version should use the release website www.bbbbbbbb.com

I made two git-branches and tried to use the same properties-file with different URIs. But each time when I commit it or merge my branches URIs are unified.

May be I can use gradel settings somehow or you can give me another peice of advice how can I user different URI for different branches and not to rewrite them each time after commit and merge.

You can use Gradle Build types for this kind of task. See http://developer.android.com/tools/building/configuring-gradle.html for more information.

Add something like the following to your build.gradle file:

buildTypes {
    debug {
        buildConfigField "String", "URL", "www.aaaaaaaaa.com"
    }
    release {
        buildConfigField "String", "URL", "www.bbbbbbbbb.com"
    }
    println "Applied basic configurations."
}

You can access this field via BuildConfig.URL in the JavaCode of your app.

You need to make following changes within your gradle:

 buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            signingConfig signingConfigs.release
        }
    }
}

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