끝에서 실행할 작업이 필요합니다. 일부는 println
라고합니다. 마지막에 작업을 실행하는 방법에 대한 여러 가지 예를 보았고 항상 다른 작업에 의존하므로 실제로 작업하는 방법을 얻지 못하고 개의 작업이 없습니다. 내가 실행 코드 실행의 조각 두 번, 한 번 실험실 맛과 하나의 자극 맛에 대한 경우와작업을 끝에서 한 번만 실행하십시오.
if (releaseBol)
{
// Some of my code
// Run twice, one for lab and other for prod
println fileName
}
가 :
MyApp:assembleRelease -PRELEASE=1
나는 코드의 평화를 필요 지금 내가 코드의 일부 조각이 단 한 번만 실행하면됩니다. 끝까지 한 번 실행해야합니다.
내 전체 Gradle을 :
import org.tmatesoft.svn.core.wc.*
apply plugin: 'com.android.application'
def BuildNumberFile = new File('./BuildNumber.txt')
def BuildNumber = 'BRND'
def _versionName = '1.0.1'
def _applicationId = 'com.myapp.android.pic'
def _versionCode = 17
def fileName = ''
def obfuscated = false
def releaseBol = false
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
lintOptions {
abortOnError false
}
def lines = BuildNumberFile.readLines()
BuildNumber = 'S'+lines.get(0)
defaultConfig {
applicationId _applicationId
minSdkVersion 15
targetSdkVersion 23
versionCode _versionCode
versionName _versionName
multiDexEnabled true
resValue 'string', 'BUILD_NUMBER_RES', BuildNumber
}
if (project.hasProperty('RELEASE') && project.ext.RELEASE == '1')
releaseBol = true
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
output.outputFile.name.replace(".apk", "-${variant.versionName}." + BuildNumber + "-" + getSvnRevision() + ".apk"))
fileName=output.outputFile.name
}
variant.assemble.doLast {
variant.outputs.each { output ->
println "aligned " + output.outputFile
println "unaligned " + output.packageApplication.outputFile
File unaligned = output.packageApplication.outputFile;
File aligned = output.outputFile
if (!unaligned.getName().equalsIgnoreCase(aligned.getName())) {
println "deleting " + unaligned.getName()
unaligned.delete()
}
}
if (releaseBol) {
// Some of my code
// Run twice, one for lab and other for prod
println fileName
}
}
}
signingConfigs {
release {
storeFile file('myapp')
storePassword "myapp123"
keyAlias 'myapp'
keyPassword "myappmobile"
}
}
productFlavors {
prod {
}
lab {
}
}
buildTypes {
release {
minifyEnabled obfuscated
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-android.txt'
signingConfig signingConfigs.release
}
}
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g"
jumboMode true
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':trunk')
}
당신이 마지막에 한 번 실행이 Gradle을 일부 println
을 추가 할 경우 그냥 날 도움이됩니다.
감사합니다, 그것은 내가 물었다 ...하지만 난 경우 (releaseBol) {} 함수 BA에 넣어 필요 releaseBol이 도달하지 않는 것입니다. 나는 BA가 "BUILD SUCCESSFUL"다음에 실행되는 것을 본다. 그러나 – Dim
@Dim 전에 필요하다. 프로젝트 범위에서'releaseBol'을 정의하고'project' 변수를 통해 참조 할 수있다. 작업 마무리자를 사용하지 않고'BUILD SUCCESSFUL' 전에 실행하는 것은 불가능하다고 생각합니다. – Opal
@Dim, 편집을 참조하십시오 - 마지막 하나는 아마도 당신이 찾고있는 것입니다. – Opal