Gradle task to publish / upload android apk to Htt

2019-05-30 15:38发布

问题:

So far we used Jenkins with Ant to build our Android APKs. The built APK, the proguard mappings.txt and some release notes get uploaded to a Http Server using curl

curl -k -F "app=@$apk_dir" -F "release_notes=@$release_notes_file" "https://ourserver.com/apps/internal/app/$app_dir/$version"

whereas app dir is assembled by some parameters from the Android Manifest

app_dir="${app_name}-${some_other_manifest_meta_data}"

As I now start switching to Gradle I want to move this to the gradle build file. I thought of a task that depends on the Android plugin assemble task and uploads the assembled apk, the release notes and the proguard file onto the Http Server.

Unfortunately the official Gradle doc and most links just describe how to upload to Maven or Ivy servers.

Would be great if someone could provide me code or at least hints on how to do this.

Thanks

回答1:

The most straightforward way to port your upload task to Gradle would be to use an Exec task.

Your task might end up looking something like this:

task upload(type:Exec) {
    executable "/bin/sh"
    args "-c", "curl -k -F [...]"
  }
}