无法使用 android studio 3.1.3 为 ApkVariantOutputImpl_Decorated 设置只读 属性 'outputFile' 的值
Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated with android studio 3.1.3
Hello friends,
I am facing one issue in app.gradle file when use proguard ruls with new android studio version is 3.1.3
. its working proper on old studio version 2.3.3
.
My full error Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=debug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
App.Gradle 文件:
android {
.....................
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
}
}
}
}
}
塔汉克斯,
输出文件 属性 不再可用于变体输出。你应该可以这样得到它:
def variantOutput = ...
def outputFile
try
{
outputFile = variantOutput.outputFile
}
catch (Exception ex)
{
def packageTask = variantOutput.packageApplication
outputFile = packageTask.outputFile
}
对于Gradle 3.0+**
android {
...
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.all {
def formattedDate = new Date().format('yyyyMMddHHmmss')
def flavor = variant.name
def versionName = variant.versionName
outputFileName = "AppName_${versionName}_${flavor}_${formattedDate}.apk"
}
}
}
}
...
}
结果:
AppName_release_1_20200121175123.apk
Hello friends,
I am facing one issue in app.gradle file when use proguard ruls with new android studio version is3.1.3
. its working proper on old studio version2.3.3
.
My full errorCannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=debug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
App.Gradle 文件:
android {
.....................
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
}
}
}
}
}
塔汉克斯,
输出文件 属性 不再可用于变体输出。你应该可以这样得到它:
def variantOutput = ...
def outputFile
try
{
outputFile = variantOutput.outputFile
}
catch (Exception ex)
{
def packageTask = variantOutput.packageApplication
outputFile = packageTask.outputFile
}
对于Gradle 3.0+**
android {
...
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.all {
def formattedDate = new Date().format('yyyyMMddHHmmss')
def flavor = variant.name
def versionName = variant.versionName
outputFileName = "AppName_${versionName}_${flavor}_${formattedDate}.apk"
}
}
}
}
...
}
结果:
AppName_release_1_20200121175123.apk