Skip to content

Instantly share code, notes, and snippets.

@dyadica
Created May 3, 2015 16:09
Show Gist options
  • Save dyadica/efe2eb19ecd9c0ff6d07 to your computer and use it in GitHub Desktop.
Save dyadica/efe2eb19ecd9c0ff6d07 to your computer and use it in GitHub Desktop.
Simple gradle file that can be used to create both .jar and .aar compiles when authoring Android plugins for Unity3D. Simply cut and paste replace the contents of the build.gradle within the app module and update the archivesBaseName property to reflect the name of your plugin.
apply plugin: "com.android.library"
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 12
targetSdkVersion 22
archivesBaseName="plugin_name"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// The following block results in a arr file being generated within build/outputs/aar
// with the name set via: archivesBaseName
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "${archivesBaseName}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.1.1'
compile files('libs/classes.jar')
}
// The following task is run to delete any existing instances of the jar
// compiled already.
task deleteOldJar(type: Delete) {
delete "release/${archivesBaseName}.jar"
}
// The following block when run exports the contents as jar
task exportJar(type: Copy) {
from("build/intermediates/bundles/release/")
into("release/")
include("classes.jar")
///Rename the jar
rename("classes.jar", "${archivesBaseName}.jar")
}
// This dependency ensures that if an instance of the compiled jar already
// exists it is deleted first before the new one is built.
exportJar.dependsOn(deleteOldJar, build)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment