Skip to content

Instantly share code, notes, and snippets.

@pboos
Last active August 7, 2020 06:38
Show Gist options
  • Star 67 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save pboos/5802233 to your computer and use it in GitHub Desktop.
Save pboos/5802233 to your computer and use it in GitHub Desktop.
Gradle stuff for Android
configurations {
apt
}
dependencies {
compile 'com.squareup.dagger:dagger:1.1.0'
apt 'com.squareup.dagger:dagger-compiler:1.1.0'
}
android.applicationVariants.all { variant ->
def aptOutput = project.file("${project.buildDir}/source/apt_generated/${variant.dirName}")
println "****************************"
println "variant: ${variant.name}"
println "manifest: ${variant.processResources.manifestFile}"
println "aptOutput: ${aptOutput}"
println "****************************"
variant.javaCompile.doFirst {
println "*** compile doFirst ${variant.name}"
aptOutput.mkdirs()
variant.javaCompile.options.compilerArgs += [
'-processorpath', configurations.apt.getAsPath(),
'-AandroidManifestFile=' + variant.processResources.manifestFile,
'-AresourcePackageName=ch.tutti.daggertest',
'-s', aptOutput
]
}
}
buildscript {
repositories {
// rather than hit central each time with this:
// mavenCentral()
// we hit our company Nexus server ont he public group
// which includes the Central Repository
// and is local, so more performant
maven {
url "http://localhost:8081/nexus/content/groups/public"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'maven'
repositories {
// we also hit Nexus for all other dependencies!
maven {
url 'http://localhost:8081/nexus/content/groups/public'
}
}
version = '0.1-SNAPSHOT'
group = 'ch.pboos.android.awesome'
uploadArchives {
repositories {
// the maven plugin features this deployer
mavenDeployer {
// we deploy to the release repository in this case
repository(url: "http://localhost:8081/nexus/content/repositories/releases") {
authentication(userName: 'admin', password: 'admin123gi')
}
snapshotRepository(url: nexusSnapshotRepo) {
// values as variable names declared in ~/.gradle/gradle.properties
authentication(userName: nexusUsername, password: nexusPassword)
}
pom.project {
artifactId 'my-awesome-library'
name 'Pure awesome!'
packaging 'aar'
}
}
}
}
android {
....
}
// run with: ./gradlew uploadArchives
apply plugin: 'android-library'
apply plugin: 'maven'
apply plugin: 'signing'
version = "1.1.2-SNAPSHOT"
group = "jp.co.cyberagent.android.gpuimage"
configurations {
archives {
extendsFrom configurations.default
}
}
signing {
required { has("release") && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
uploadArchives {
configuration = configurations.archives
repositories.mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: sonatypeRepo) {
authentication(userName: sonatypeUsername, password: sonatypePassword)
}
snapshotRepository(url: sonatypeSnapshotRepo) {
authentication(userName: sonatypeUsername, password: sonatypePassword)
}
pom.project {
artifactId 'gpuimage-library'
name 'GPUImage for Android Library'
packaging 'aar'
description 'Image filters for Android with OpenGL (based on GPUImage for iOS)'
url 'https://github.com/cyberagent/android-gpuimage/'
scm {
url 'scm:git@github.com:CyberAgent/android-gpuimage.git'
connection 'scm:git@github.com:CyberAgent/android-gpuimage.git'
developerConnection 'scm:git@github.com:CyberAgent/android-gpuimage.git'
}
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'pboos'
name 'Patrick Boos'
email 'patrickboos85@gmail.com'
}
}
}
}
}
android {
...
}
# ~/.gradle/gradle.properties
signing.keyId=123456 # from gpg --list-keys
signing.password=password # password of that key
signing.secretKeyRingFile=/Users/boos_patrick/.gnupg/secring.gpg
sonatypeRepo=https://oss.sonatype.org/service/local/staging/deploy/maven2/
sonatypeSnapshotRepo=https://oss.sonatype.org/content/repositories/snapshots/
sonatypeUsername=sonatype_user
sonatypePassword=your_difficult_password
//////////////
// NDK Support
//////////////
// If using this, Android studio will fail run the following to set the environment variable for android studio:
// launchctl setenv ANDROID_NDK_HOME /Users/boos_patrick/Development/Android/android-ndk-r8e
// otherwise remove the dependsOn part and run ./gradlew buildNative from the command line
task copyNativeLibs(type: Copy, dependsOn: 'buildNative') {
dependsOn 'buildNative'
from(new File('libs')) { include '**/*.so' }
into new File(buildDir, 'native-libs')
}
tasks.withType(Compile) { compileTask -> compileTask.dependsOn copyNativeLibs }
clean.dependsOn 'cleanCopyNativeLibs'
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniDir new File(buildDir, 'native-libs')
}
task buildNative(type: Exec) {
if (System.env.ANDROID_NDK_HOME != null) {
def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
commandLine ndkBuild
} else {
doLast {
println '##################'
println 'Skipping NDK build'
println 'Reason: ANDROID_NDK_HOME not set.'
println '##################'
}
}
}
signingConfigs {
release {
def env = System.getenv()
if (env['GRADLE_KEYSTORE_FILE'] != null) {
storeFile file(env['GRADLE_KEYSTORE_FILE'])
storePassword env['GRADLE_KEYSTORE_PASSWORD']
keyAlias env['GRADLE_KEYSTORE_KEY_ALIAS']
keyPassword env['GRADLE_KEYSTORE_KEY_PASSWORD']
} else {
println ("##################")
println ("No keystore for release set.")
println ("Set GRADLE_KEYSTORE_FILE, GRADLE_KEYSTORE_PASSWORD,"
+ "GRADLE_KEYSTORE_KEY_ALIAS and GRADLE_KEYSTORE_KEY_PASSWORD")
println ("##################")
}
}
}
buildTypes {
release {
signingConfig signingConfigs.release
zipAlign true
}
}
task spoon(type: JavaExec, dependsOn: ["assembleDebug", "assembleTest"]) {
main = "-jar"
args relativePath("../spoon-runner-1.0.6-SNAPSHOT-jar-with-dependencies.jar")
args "--apk"
args relativePath("build/apk/sample-app-debug-unaligned.apk")
args "--test-apk"
args relativePath("build/apk/sample-app-test-unaligned.apk")
args "--output"
args "build/spoon"
logger.info "main=${main},classpath=${classpath},args=${args}"
}
// UTF-8
tasks.withType(Compile) {
options.encoding = 'UTF-8'
}
@chrisjenx
Copy link

adding Jar task would be great too? Sometimes libs without resources are just as good built as jars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment