有没有办法从app / build.gradle文件运行gradle任务,这样当我构建发布APK任务" firebaseUploadReleaseProguardMapping"将自动运行。
答案 0 :(得分: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),firebaseUploadReleaseProguardMapping
和archiveRelease
。 publishApkRelease
取决于assembleRelease
。
您需要致电./gradlew release
,它会构建您的发布版本,将apk上传到Google Play,将映射文件上传到Firebase并归档apk和映射文件的副本。