Android Gradle 3.0.0-alpha2 플러그인, 읽기 전용 속성 'outputFile'의 값을 설정할 수 없습니다.
나는이 코드를 사용하고 있었다
applicationVariants.all { variant ->
variant.outputs.each { output ->
def SEP = "_"
def flavor = variant.productFlavors[0].name
def buildType =
variant.variantData.variantConfiguration.buildType.name
def version = variant.versionName
def date = new Date()
def formattedDate = date.format('ddMMyy_HHmm')
def newApkName = PROJECT_NAME + SEP + flavor + SEP + buildType + SEP + version + SEP + formattedDate + ".apk"
def file = new File(newApkName)
output.outputFile = file
}
}
새 apk를 빌드 할 때 apk 파일의 이름을 변경하려면 Android Studio 3.0 Canary 2를 사용하기 때문에이 오류가 나타납니다.
읽기 전용 속성 'outputFile'의 값을 설정할 수 없습니다 ....
로 3.0 마이그레이션 가이드 플러그인 안드로이드 제안한다 :
all()
대신 사용each()
- 파일 이름 만 변경
outputFileName
하는output.outputFile
경우 대신 사용 (즉, 귀하의 경우)
가이드의 예 :
// If you use each() to iterate through the variant objects,
// you need to start using all(). That's because each() iterates
// through only the objects that already exist during configuration time—
// but those object don't exist at configuration time with the new model.
// However, all() adapts to the new model by picking up object as they are
// added during execution.
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${variant.name}-${variant.versionName}.apk"
}
}
아래를 참조하십시오.
applicationVariants.all { variant ->
variant.outputs.all { output ->
def newApkName = applicationId + "-" + variant.versionName + "(" + variant.versionCode + ")" + ".apk";
outputFileName = new File("${project.projectDir}/../outputs/apks/" + variant.name, newApkName);
}
}
아래 코드는 android studio canary 3.0.0-alpha3에서 나를 위해 일하고 있습니다.
android.applicationVariants.all {
variant.outputs.all {
def newApkName
newApkName = "APPLICATION_NAME-" + defaultConfig.versionName + "-" + defaultConfig.versionCode".apk"
outputFileName = newApkName;
}
}
이것은 apk 파일 이름을 변경합니다.
이것이이 질문 의 완전한 예 입니다.
Only you have to paste in your gradle 3.0+ after productFlavours
android.applicationVariants.all { variant ->
variant.outputs.all {
def SEP = "_"
def flavor = variant.productFlavors[0].name
def buildType = variant.variantData.variantConfiguration.buildType.name
def version = variant.versionName
def versionCode = variant.versionCode
def date = new Date();
def formattedDate = date.format('ddMMyy_HHmm')
outputFileName = "${flavor}${SEP}${buildType}${SEP}${version}${SEP}${versionCode}${SEP}${formattedDate}.apk"
}
}
I founded gradle 3.0 is no longer work. source link
However, more complicated tasks that involve accessing outputFile objects no longer work. That's because variant-specific tasks are no longer created during the configuration stage. This results in the plugin not knowing all of its outputs up front, but it also means faster configuration times.
then I used command gradlew
to compile project.and cp
the output apk to my specified path
In Execute shell, i putted below command.
./gradlew clean assembleDebug
cp $WORKSPACE/app/build/outputs/apk/debug/*.apk $WORKSPACE/JenkinsApk
I had the same problem. Error "Cannot set the value of read-only property 'outputFile'....""
So what I did is changing the version of the Android Plugin Repository to 2.3.3 in the Project Structure window. It works now and the error desappearded.
Later, do Clean and Rebuild for the project and that's it
Hope this would be helpful for you.
This is a year and half since the question was asked but maybe this will help someone (like me) who discovers this post first. I believe the answer to change the file name and directory was answered here.
applicationVariants.all { variant -> variant.outputs.all { output -> def relativeRootDir = output.packageApplication.outputDirectory.toPath() .relativize(rootDir.toPath()).toFile() output.outputFileName = new File( "$relativeRootDir/release", newOutputName) } }
After update to Android Studio 3.0.0 and use the new gradle, now, the output of apks will be distributed in directories by flavors name and build types.
'programing tip' 카테고리의 다른 글
require (vendor / autoload.php) : 스트림을 열지 못했습니다. (0) | 2020.09.18 |
---|---|
Angular 2의 특정 경로에 대해 RouteReuseStrategy shouldDetach를 구현하는 방법 (0) | 2020.09.18 |
터미널에서 bash 스크립트를 어떻게 실행합니까? (0) | 2020.09.18 |
ImageView로 Android 페이드 인 및 페이드 아웃 (0) | 2020.09.18 |
Oracle SQL Developer SQL 워크 시트 창에서 텍스트 인쇄 (0) | 2020.09.18 |