2016-12-28 49 views

回答

1

可以使用dependsOn例如(您app/build.gradle):

apply plugin: 'com.android.application' 
apply plugin: 'com.google.firebase.firebase-crash' 

android { 

} 

dependencies { 

} 


task release 

task archiveRelease(type: Copy) { 
    from './build/outputs/apk', './build/outputs/' 
    into "../releases/${rootProject.ext.configuration.version_code}" 
    include('app-release.apk', 'mapping/release/mapping.txt') 
    rename('app-release.apk', "${rootProject.ext.configuration.package}_${rootProject.ext.configuration.version_name}_${rootProject.ext.configuration.version_code}.apk") 
} 

project.afterEvaluate { 

    dependencyUpdates.dependsOn clean 
    assembleRelease.dependsOn clean 

    def publishApkRelease = project.tasks.getByName("publishApkRelease") 
    publishApkRelease.dependsOn assembleRelease 

    release.dependsOn publishApkRelease, firebaseUploadReleaseProguardMapping, archiveRelease 
} 

我創建了一個名爲release新任務。它取決於publishApkRelease(來自gradle-play-publisher),firebaseUploadReleaseProguardMappingarchiveRelease。而publishApkRelease取決於assembleRelease

在ned你只需調用./gradlew release,它會構建你的發佈版本,將apk上傳到Google play,將映射文件上傳到Firebase並存檔apk和映射文件的副本。