我正在尝试在gradle自动生成的APK文件名中设置特定的版本号.
现在gradle生成myapp-release.apk但我希望它看起来像myapp-release-1.0.apk.
我尝试过重命名看起来很乱的选项.有一个简单的方法吗?
buildTypes {
release {
signingConfig signingConfigs.release
applicationVariants.each { variant ->
def file = variant.outputFile
variant.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
}
}
Run Code Online (Sandbox Code Playgroud)
我试过上面的代码没有运气.有什么建议?(使用gradle 1.6)
我有一个Android项目,它使用Gradle进行构建过程.现在我想添加两个额外的构建类型登台和生产,所以我的build.gradle包含:
android {
buildTypes {
release {
runProguard false
proguardFile getDefaultProguardFile('proguard-android.txt')
}
staging {
signingConfig signingConfigs.staging
applicationVariants.all { variant ->
appendVersionNameVersionCode(variant, defaultConfig)
}
}
production {
signingConfig signingConfigs.production
}
}
}
Run Code Online (Sandbox Code Playgroud)
和我的appndVersionNameVersionCode看起来像:
def appendVersionNameVersionCode(variant, defaultConfig) {
if(variant.zipAlign) {
def file = variant.outputFile
def fileName = file.name.replace(".apk", "-" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk")
variant.outputFile = new File(file.parent, fileName)
}
def file = variant.packageApplication.outputFile
def fileName = file.name.replace(".apk", "-" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk")
variant.packageApplication.outputFile = …Run Code Online (Sandbox Code Playgroud) 我希望从gradle重命名我的apk.我在构建中有以下几行
applicationVariants.all { variant ->
def file = variant.outputFile
def filename = file.name.replace("SomeXXX", "SomeYYY")
variant.outputFile = new File(file.parent, filename)
}
Run Code Online (Sandbox Code Playgroud)
这成功地重命名了apks而不是未对齐的apks.请有人对此有所了解.
我想使用自定义名称生成输出 apk 文件。例如。默认情况下,android studio 生成“app-debug.apk”文件。但我希望它是 - "MyAppName_myCurrentProdFlavour_vMyVersionName.apk" 如何使用模块的build.gradle文件执行此操作
我有以下应用程序 build.gradle
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "io.gresse.hugo.anecdote"
minSdkVersion 16
targetSdkVersion 23
versionCode 12
versionName "1.0.0"
}
buildTypes {
release {
archivesBaseName = "anecdote-" + defaultConfig.versionName
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
archivesBaseName = "anecdote-DEBUGDEBUGDEBUG-"
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我执行 ./gradlew assembleRelease assembleDebug
输出 .apk 是:
- anecdote-DEBUGDEBUGDEBUG-debug-unaligned.apk
- anecdote-DEBUGDEBUGDEBUG-debug.apk
- anecdote-DEBUGDEBUGDEBUG-release-unaligned.apk
-anecdote-DEBUGDEBUGDEBUG-release.apk
我想要的:
- anecdote-DEBUGDEBUGDEBUG-debug-unaligned.apk
- anecdote-DEBUGDEBUGDEBUG-debug.apk
- anecdote-1.0.0-release-unaligned.apk
-anecdote-1.0.0-release.apk
有什么方法可以将archiveBaseName应用于特定的构建类型还是一个错误?
谢谢,