I'm trying to create a CI build that builds a release version of an android app and upload the resulting apk to a maven sonatype nexus repo.
When I run assembleRelease, the apk is generated,signed,runs proguard,and is located in build/outputs/apk/app-release.apk
in order to upload to nexus, I've used this gradle plugin: https://github.com/chrisbanes/gradle-mvn-push with one difference, that I used POM_PACKAGING=apk
I run : gradle uploadArchives and it works fine,it does upload an apk to nexus, but its not the same file as in build/outputs/apk/app-release.apk (different creation dates).
meaning its either doing whatever assembleRelease does or it just archives the source but misses some of the required actions needed for an android app.
the gradle plugin defines these artificats:
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
maybe I should add a file artifact to build/outputs/apk/app-release.apk?
I tried the mentioned solution but I always had a "apk file does not exist" problem when Jenkins tried to upload the apk-file to our nexus repository.
In the documentation of the gradle plugin the path starts with the "build" folder. (https://docs.gradle.org/current/userguide/artifact_management.html)
I tried to inject some env variables to the path but jenkins was always complaining "file not found". I came up with this solution and it simply works.
uploadArchives {
repositories {
mavenDeployer {
repository(url: "https://repo.domain.com/content/repositories/snapshots") {
authentication(userName: nexususername, password: nexuspassword)
}
pom.project {
version "0.0.1-SNAPSHOT"
artifactId "android-artifact"
name "android-name"
groupId "com.domain.foo.bar"
}
}
}
}
// /data/jenkins_work/NAME_OF_THE_BUILD_JOB/artifact/app/build/outputs/apk/app-debug.apk
def apk = file('app/build/outputs/apk/yourapp.apk')
artifacts {
archives apk
}
We publish our APK files to our local Nexus repository using gradle. This is what I've come up with. This example demonstrated using a "googlePlay" build flavor.
// make sure the release builds are made before we try to upload them.
uploadArchives.dependsOn(getTasksByName("assembleRelease", true))
// create an archive class that known how to handle apk files.
// apk files are just renamed jars.
class Apk extends Jar {
def String getExtension() {
return 'apk'
}
}
// create a task that uses our apk task class.
task googlePlayApk(type: Apk) {
classifier = 'googlePlay'
from file("${project.buildDir}/outputs/apk/myApp-googlePlay-release.apk")
}
// add the item to the artifacts
artifacts {
archives googlePlay
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With