android studio 3.1: build:gradle:3.1.0 - Absolute path are not supported when setting an output file name

后端 未结 7 931
囚心锁ツ
囚心锁ツ 2020-12-05 19:32

When I use Android Studio 3.0 and I use the next version of Android Gradle Plugin in project/build.gradle:

cl         


        
7条回答
  •  庸人自扰
    2020-12-05 19:42

    The simplest solution for Android Gradle plugin 3.4.0+ is as below:

    Assemble/concatenate your new file name:

    def newFileName = "assemble-your-new-file-name"
    

    Then, simply assign it back.

    outputFileName = newFileName
    

    More specifically is as following

    android.applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // Redirect your apks to new defined location to outputDirPath
            def outputDirPath = new File("${project.rootDir.absolutePath}/apks/${variant.flavorName}/${variant.buildType.name}")
            variant.packageApplicationProvider.get().outputDirectory = outputDirPath
    
            def apkFileName = "${rootProject.name}_${android.defaultConfig.versionName}.apk"
            output.outputFileName = apkFileName // directly assign the new name back to outputFileName
        }
    }
    

提交回复
热议问题