1.配置 productFlavors
productFlavors {
_dev {//开发环境
applicationId "com.demo.video.dev"
//设置baseUrl 使用方法Application.getContext().getResources().getString(R.string.API_SERVER)
resValue "string","API_SERVER","www.baidu.dev.com"
manifestPlaceholders = [app_name: "U视频_dev"]
}
_test {//测试环境
applicationId "com.demo.video.test"
resValue "string","API_SERVER","www.baidu.test.com"
manifestPlaceholders = [app_name: "U视频_test"]
}
_prod {//正式环境
applicationId "com.demo.video"
resValue "string","API_SERVER","www.baidu.com"
manifestPlaceholders = [app_name: "U视频"]
}
}
2.配置APK输入路径 (可配置或者不配置 默认在build/outputs下)
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
debuggable false
}
debug {
minifyEnabled false
signingConfig signingConfigs.config
debuggable true
}
//打包输出
applicationVariants.all { variant ->
def fileName
def buildName
variant.outputs.each { output ->
def outputFile = output.outputFile
variant.productFlavors.each { product ->
buildName = product.name //获取渠道名字
}
if (outputFile != null && outputFile.name.endsWith('.apk')) {
//打包后的apk名称 : UVideo_V1.0_test_0808_1109.apk
fileName = "UVideo_V${defaultConfig.versionName}" + buildName + "_" + createDate() + ".apk"
output.outputFile = new File("apk" + '/', fileName)
}
}
}
}
//获取时间的方法
def createDate() {
return new Date().format("MMdd_HHmm", TimeZone.getTimeZone("GMT+8"))
}
3.打包
使用AndroidStudio可在Terminal下输入./gradlew assembleRelease
或者输入对应的./gradlew assemble_dev
也可在右侧Gradle中选中要打包的版本执行
4.安装/测试应用
1.使用ADB
可在终端下输入 adb install apk路径
即可
2.使用Gradle
在右侧Gradle下选择install目录下对应的版本运行即可
网友评论