def VARIANT_NAME = 'xw4' def INITIAL_CLIENT_VERS = 6 def CHAT_ENABLED = true def THUMBNAIL_ENABLED = true def LIBS_DEBUG = 'libs-debug' def LIBS_RELEASE = 'libs-release' apply plugin: 'com.android.application' dependencies { compile files('../libs/gcm.jar') } android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "org.eehouse.android.xw4" minSdkVersion 7 targetSdkVersion 14 } // Rename all output artifacts to include version information applicationVariants.all { variant -> renameArtifact(variant) } signingConfigs { release { storeFile file(System.getenv("HOME") + "/.keystore") keyAlias "mykey" // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notReal" keyPassword "notReal" } } buildTypes { release { signingConfig signingConfigs.release debuggable false minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { debuggable true } } sourceSets { // Use symlinks instead of setting non-conventional // directories here. AS doesn't respect what's set here: it'll // compile, but post-install app launch and source-level // debugging don't work. release { jniLibs.srcDir "../$LIBS_RELEASE" } debug { jniLibs.srcDir "../$LIBS_DEBUG" } } lintOptions { abortOnError false } productFlavors { } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) } task genVers(type: Exec) { workingDir '../' commandLine '../scripts/genvers.sh', VARIANT_NAME, INITIAL_CLIENT_VERS, CHAT_ENABLED, THUMBNAIL_ENABLED } task mkImages(type: Exec) { workingDir '../' commandLine '../scripts/mkimages.sh' } task copyStrings(type: Exec) { workingDir '../' commandLine '../scripts/copy-strings.py' } task ndkSetup(type: Exec) { workingDir '../' commandLine "../scripts/ndksetup.sh" } task genGcmid(type: Exec) { workingDir '../' commandLine '../scripts/gen_gcmid.sh', '-o', "src/org/eehouse/android/$VARIANT_NAME/GCMConsts.java", '-v', "$VARIANT_NAME" } task myPreBuild(dependsOn: ['genVers', 'ndkSetup', 'mkImages', 'copyStrings', 'mkXml', 'genGcmid']) { } preBuild.dependsOn myPreBuild task ndkBuildDebug(type: Exec) { workingDir '../' commandLine '../scripts/ndkbuild.sh', '-j3', "CHAT_ENABLED=$CHAT_ENABLED", "THUMBNAIL_ENABLED=$THUMBNAIL_ENABLED", 'BUILD_TARGET=debug', "INITIAL_CLIENT_VERS=$INITIAL_CLIENT_VERS", "VARIANT=$VARIANT_NAME", "NDK_LIBS_OUT=$LIBS_DEBUG", 'NDK_OUT=./obj-debug' } task ndkBuildRelease(type: Exec) { workingDir '../' commandLine '../scripts/ndkbuild.sh', '-j3', "CHAT_ENABLED=$CHAT_ENABLED", "THUMBNAIL_ENABLED=$THUMBNAIL_ENABLED", 'BUILD_TARGET=release', "INITIAL_CLIENT_VERS=$INITIAL_CLIENT_VERS", "VARIANT=$VARIANT_NAME", "NDK_LIBS_OUT=$LIBS_RELEASE", 'NDK_OUT=./obj-release' } task mkXml(type: Exec) { workingDir '../' commandLine '../scripts/mk_xml.py', '-o', "src/org/eehouse/android/$VARIANT_NAME/loc/LocIDsData.java", '-t', "debug", '-v', "$VARIANT_NAME" } afterEvaluate { compileReleaseNdk.dependsOn ndkBuildRelease compileDebugNdk.dependsOn ndkBuildDebug } task askForPassword << { def password = System.getenv("ANDROID_KEY_PASS") if (null == password || 0 == password.length()) { if ( null != System.console() ) { password = new String(System.console() .readPassword("ANDROID_KEY_PASS not set; " + "Keystore password: ")) } else { password = null println( "ANDROID_KEY_PASS not set and no console; " ) println( "sign it yerself later. (Or you might try" ) println( " running gradlew with the --no-daemon flag)" ) } } if ( null != password ) { android.signingConfigs.release.storePassword = password android.signingConfigs.release.keyPassword = password } } tasks.whenTaskAdded { theTask -> if (theTask.name.equals("packageRelease")) { theTask.dependsOn "askForPassword" } } def getVersionName() { try { def stdout = new ByteArrayOutputStream() exec { commandLine 'git', 'describe', '--dirty' standardOutput = stdout } return stdout.toString().trim() } catch (ignored) { return null; } } def renameArtifact(variant) { variant.outputs.each { output -> def name = String.format( "XWords4-%s-%s.apk", variant.name, getVersionName() ) output.outputFile = new File( (String)output.outputFile.parent, (String)name ) } }