相关疑难解决方法(0)

如何使用gradle在APK文件名中设置versionName?

我正在尝试在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 build gradle apk android-gradle-plugin

159
推荐指数
9
解决办法
8万
查看次数

用Gradle更改apk名称

我有一个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)

android gradle apk android-gradle-plugin

41
推荐指数
3
解决办法
4万
查看次数

在gradle中重命名apk

我希望从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.请有人对此有所了解.

android gradle apk

10
推荐指数
1
解决办法
3270
查看次数

如何在 Android Studio 中生成具有自定义名称的输出 APK 文件?

我想使用自定义名称生成输出 apk 文件。例如。默认情况下,android studio 生成“app-debug.apk”文件。但我希望它是 - "MyAppName_myCurrentProdFlavour_vMyVersionName.apk" 如何使用模块的build.gradle文件执行此操作

android android-studio build.gradle android-gradle-plugin

6
推荐指数
2
解决办法
3506
查看次数

应用于所有构建类型的 archiveBaseName

我有以下应用程序 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应用于特定的构建类型还是一个错误?

谢谢,

android gradle android-gradle-plugin

5
推荐指数
1
解决办法
1506
查看次数