Gradle

Android Gradle配置debug和release參數

1.添加buildType並設置參數

buildTypes {
   release {
       //release參數
       buildConfigField('String', 'ServerAddress', "\"https://badgameshow.com/\"")
       minifyEnabled false
       proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
       signingConfig signingConfigs.release
   }
   debug {
       //debug參數
       buildConfigField('String', 'ServerAddress', "\"https://badgameshow.com/flytest/\"")
       signingConfig signingConfigs.debug
   }
}

2.添加簽名

signingConfigs {
   release {
       //路徑是ProjectName\app\test.jks
       storeFile file("test.jks")
       keyAlias "test"
       keyPassword "qqq11111"
       storePassword "qqq11111"
   }
   debug {
       //路徑是ProjectName\app\test.jks
       storeFile file("test.jks")
       keyAlias "test"
       keyPassword "qqq11111"
       storePassword "qqq11111"
   }
}

3.取得參數

url.text = BuildConfig.BUILD_TYPE + "\n" + BuildConfig.ServerAddress

4.選擇版本與BuildConfig路徑

5.效果展示

發表迴響