Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run firebaseUploadReleaseProguardMapping task from app/build.gradle file

Is there any way to run gradle task from app/build.gradle file, so that when I build release APK task "firebaseUploadReleaseProguardMapping" will run automatically.

like image 597
Tigran Sarkisian Avatar asked Nov 08 '22 04:11

Tigran Sarkisian


1 Answers

You can use dependsOn for example (your 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
}

I created a new task called release. It depends on publishApkRelease (comes from gradle-play-publisher), firebaseUploadReleaseProguardMapping and archiveRelease. And publishApkRelease depends on assembleRelease.

At the ned you just call ./gradlew release and it will build your release version, uploads the apk to Google play, the mapping file to Firebase and archive a copy of the apk and mapping file.

like image 192
Ralph Bergmann Avatar answered Nov 29 '22 21:11

Ralph Bergmann