Skip to content

Instantly share code, notes, and snippets.

@mariusk
Created March 20, 2014 09:59
Show Gist options
  • Save mariusk/9660603 to your computer and use it in GitHub Desktop.
Save mariusk/9660603 to your computer and use it in GitHub Desktop.
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
signingConfigs {
debug {
storeFile file("debug.keystore")
}
release {
storeFile file("my-release-key.keystore")
}
}
buildTypes {
release {
debuggable false
jniDebugBuild false
signingConfig signingConfigs.release
runProguard true
//proguardFile getDefaultProguardFile('proguard-android.txt')
proguardFile '../proguard-android-optimize-local.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('/usr/local/share/java/kawa.jar')
}
public class KawaCompileTask extends DefaultTask {
@InputFiles
Set<File> source = [] as Set;
String classpath;
@TaskAction
void compile() {
// Collect all *.scm source files (for sending to kawa).
List <File> files = source.collect { File source ->
if (!source.isDirectory())
return source
return project.fileTree(source) {
include "**/*.scm"
}.files
}.flatten()
// Figure out where the android sdk is located, and create a path to the proper
// android.jar from it.
//
// Adapted from:
// http://stackoverflow.com/questions/20203787/
// access-sdk-dir-value-in-build-gradle-after-project-evaluation
def sdkDir = null
def androidJarPath
def rootDir = project.rootDir
def localProperties = new File(rootDir, "local.properties")
if (localProperties.exists()) {
Properties properties = new Properties()
localProperties.withInputStream { instr ->
properties.load(instr)
}
sdkDir = properties.getProperty('sdk.dir')
androidJarPath = sdkDir + "/platforms/" + project.android.compileSdkVersion + "/android.jar"
}
// Check that we have what is needed to compile before proceeding.
if ((files.size() == 0) || (null == sdkDir))
return;
// Compile sources.
project.exec {
environment CLASSPATH: androidJarPath
workingDir "src/main/kawa"
//executable = "pwd" // /Users/marius/AndroidStudioProjects/KawaTest/app
executable = "kawa"
// Flags to the kawa compiler, set destination dir for class files
// and list files to be compiled.
args "-d", ext.outputDir, "-C"
args += files
println "kawa invoked with args: "+args
}
}
}
task kawaAssembleDebug(type: KawaCompileTask) {
//getLogger().trace("======= kawacompile")
source += file("src/main")
ext.outputDir = file("$buildDir/classes/debug")
}
task kawaAssembleRelease(type: KawaCompileTask) {
//getLogger().trace("======= kawacompile")
source += file("src/main")
ext.outputDir = file("$buildDir/classes/release")
}
assembleDebug.dependsOn kawaAssembleDebug
//assembleRelease.dependsOn kawaAssembleRelease
//kawaAssembleDebug.dependsOn assembleDebug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment