Android Studio: Switching a URL depending on buildtype? (used for testing in debug /release)

后端 未结 2 1828
一向
一向 2021-01-31 18:01

I have been reading something about variants and buildtypes and I don\'t know if I am understanding it right but I would like to store a URL for locahost (testing) and one for p

2条回答
  •  遇见更好的自我
    2021-01-31 18:41

       buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            buildConfigField "String", "BASE_URL", '"url1"'
            debuggable false
    
        }
    
       debug {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            buildConfigField "String", "BASE_URL", '"url2"'
            debuggable true
    
     }
    

    This you need to do in the gradle and to make run two applications(release and debug) in a same phone just add

    applicationIdSuffix ".debug"

    in debug portion. As the package name will be different. This worked for me.

提交回复
热议问题