/* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */ /* * Copyright 2015 - 2023 by Eric House (xwords@eehouse.org). All rights * reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ def INITIAL_CLIENT_VERS = 10 def VERSION_CODE_BASE = 194 def VERSION_NAME = '4.4.198' def BUILD_INFO_NAME = "build-info.txt" def LAST_COMMIT_FILE = "last-commit.txt" // Trying to support older devices (pre KitKat) while moving KitKat and beyond // to the newer version of the Paho MQTT client library that, with luck, will // crash less. I expect there will be two tags and two releases per set of // changes: first one with USE_KITKAT_MQTT changed to false, and then // immediately after one with it set to true. I have no idea how to do this on // f-droid, so for now JellyBean and earlier will be abandoned there. def USE_KITKAT_MQTT = true // Not all variants use the same BT_UUID. Those with the same talk to // each other def XW_UUID = '"7be0d084-ff89-4d6d-9c78-594773a6f963"' // from comms.h def XWD_UUID = '"b079b640-35fe-11e5-a432-0002a5d5c51b"' // from comms.h // AID must start with F (first 4 bits) and be from 5 to 16 bytes long def NFC_AID_XW4 = "FC8FF510B360" def NFC_AID_XW4d = "FDDA0A3EB5E5" // Get the git revision we're using. Since fdroid modifies files as // part of its build process -dirty will always be added, confusing // users. So add that for the non-fdroid case. if (! project.hasProperty('GITREV')) { ext.GITREV = 'git describe --tags --dirty'.execute().text.trim() } def GITREV_SHORT = "git rev-parse --short HEAD".execute().text.trim() // Make CURTAG non-empty IFF we're at a tag (release build) def CURTAG = "git describe --exact-match".execute().text.trim() // print "CURTAG: " + CURTAG + "\n" apply plugin: 'com.android.application' repositories { google() mavenCentral() } android { compileOptions { sourceCompatibility 1.8 targetCompatibility 1.8 } // Specify buildToolsVersion so gradle will inform when the // default changes and .travis.yml can be kept in sync buildToolsVersion '28.0.3' ndkVersion '21.4.7075529' defaultConfig { // HostApduService requires 19. But is it a problem? if ( USE_KITKAT_MQTT ) { minSdkVersion 19 // Required for paho client > 3:1.1.+ } else { minSdkVersion 14 } versionCode VERSION_CODE_BASE versionName VERSION_NAME } // Rename all output artifacts to include version information applicationVariants.all { variant -> // renameArtifact(variant) // variant.buildConfigField "String", "FIELD_NAME", "\"my String\"" // We need both of these because xwprefs.xml can't reference // the BuildConfig constant variant.buildConfigField "String", "GIT_REV", "\"$GITREV\"" variant.buildConfigField "String", "GITREV_SHORT", "\"$GITREV_SHORT\"" // def stamp = Long.valueOf('date +\'%s\''.execute().text.trim()); def stamp = Math.round(System.currentTimeMillis() / 1000) variant.buildConfigField "long", "BUILD_STAMP", "$stamp" variant.buildConfigField "short", "CLIENT_VERS_RELAY", "$INITIAL_CLIENT_VERS" } /* Variants: * * GPlay: for the Google Play store, include FCM but not SMS-data. * * FDroid: for the f-droid store, includes SMS-data but not FCM. * * Foss: released via SourceForge and Github, and auto-upgraded * within the app. Includes both SMS-data and FCM */ flavorDimensions "variant"//, "abi" productFlavors { all { android { targetSdkVersion 31 compileSdkVersion 31 } buildConfigField "String", "JNI_LIB_NAME", "\"xwjni\"" buildConfigField "String", "DB_NAME", "\"xwdb\"" buildConfigField "String", "BUILD_INFO_NAME", "\"${BUILD_INFO_NAME}\"" buildConfigField "boolean", "IS_TAGGED_BUILD", "${CURTAG}" == '' ? "false" : "true" resValue "string", "invite_prefix", "/and/" resValue "string", "conf_prefix", "/cnf/" resValue "string", "newgame_scheme", "newxwgame" buildConfigField "boolean", "UDP_ENABLED", "true" buildConfigField "boolean", "REPORT_LOCKS", "false" buildConfigField "boolean", "LOG_LIFECYLE", "false" buildConfigField "boolean", "ATTACH_SUPPORTED", "false" buildConfigField "boolean", "NON_RELEASE", "DEBUG || !IS_TAGGED_BUILD" buildConfigField "boolean", "HAVE_KNOWN_PLAYERS", "true" buildConfigField "boolean", "FOR_FDROID", "false" buildConfigField "boolean", "HAVE_PASSWORD", "false" buildConfigField "boolean", "NO_NEW_RELAY", "true" buildConfigField "boolean", "LOCUTILS_ENABLED", "false" buildConfigField "String", "LAST_COMMIT_FILE", "\"$LAST_COMMIT_FILE\"" buildConfigField "int", "BAD_COUNT", "2" resValue "string", "nbs_port", "0" } xw4GPlay { dimension "variant" applicationId "org.eehouse.android.xw4GPTest" manifestPlaceholders = [ APP_ID: applicationId ] resValue "string", "app_name", "DoNotRelease" buildConfigField "boolean", "NON_RELEASE", "true" buildConfigField "boolean", "WIDIR_ENABLED", "false" buildConfigField "String", "VARIANT_NAME", "\"Google Play Store\"" buildConfigField "int", "VARIANT_CODE", "1" buildConfigField "String", "NFC_AID", "\"${NFC_AID_XW4}\"" resValue "string", "nfc_aid", "$NFC_AID_XW4" externalNativeBuild.ndkBuild.cFlags += ['-DVARIANT_xw4GPlay'] externalNativeBuild.ndkBuild.arguments += ['XW_BT_UUID=' + XW_UUID] } xw4fdroid { dimension "variant" applicationId "org.eehouse.android.xw4" manifestPlaceholders = [ APP_ID: applicationId ] resValue "string", "app_name", "CrossWords" resValue "string", "nbs_port", "3344" buildConfigField "boolean", "WIDIR_ENABLED", "false" buildConfigField "String", "VARIANT_NAME", "\"F-Droid\"" buildConfigField "int", "VARIANT_CODE", "2" buildConfigField "boolean", "FOR_FDROID", "true" buildConfigField "String", "NFC_AID", "\"${NFC_AID_XW4}\"" resValue "string", "nfc_aid", "$NFC_AID_XW4" externalNativeBuild.ndkBuild.cFlags += ['-DVARIANT_xw4fdroid'] externalNativeBuild.ndkBuild.arguments += ['XW_BT_UUID=' + XW_UUID] } xw4d { dimension "variant" buildConfigField "String", "DB_NAME", "\"xwddb\"" applicationId "org.eehouse.android.xw4dbg" resValue "string", "app_name", "CrossDbg" resValue "string", "nbs_port", "3345" resValue "string", "invite_prefix", "/andd/" resValue "string", "conf_prefix", "/cnfd/" resValue "string", "newgame_scheme", "newxwgamed" buildConfigField "boolean", "WIDIR_ENABLED", "true" buildConfigField "String", "VARIANT_NAME", "\"Dev/Debug\"" buildConfigField "int", "VARIANT_CODE", "3" buildConfigField "boolean", "REPORT_LOCKS", "true" buildConfigField "String", "NFC_AID", "\"${NFC_AID_XW4d}\"" resValue "string", "nfc_aid", "$NFC_AID_XW4d" externalNativeBuild.ndkBuild.cFlags += ['-DVARIANT_xw4d'] externalNativeBuild.ndkBuild.arguments += ['XW_BT_UUID=' + XWD_UUID] } xw4dGPlay { dimension "variant" applicationId "org.eehouse.android.xw4dbg" buildConfigField "String", "DB_NAME", "\"xwddb\"" resValue "string", "app_name", "CrossDbg" resValue "string", "invite_prefix", "/andd/" resValue "string", "conf_prefix", "/cnfd/" resValue "string", "newgame_scheme", "newxwgamed" buildConfigField "boolean", "WIDIR_ENABLED", "true" buildConfigField "String", "VARIANT_NAME", "\"Dev/Debug GPlay\"" buildConfigField "int", "VARIANT_CODE", "4" buildConfigField "boolean", "REPORT_LOCKS", "true" buildConfigField "String", "NFC_AID", "\"${NFC_AID_XW4d}\"" resValue "string", "nfc_aid", "$NFC_AID_XW4d" externalNativeBuild.ndkBuild.cFlags += ['-DVARIANT_xw4dGPlay'] externalNativeBuild.ndkBuild.arguments += ['XW_BT_UUID=' + XWD_UUID] } xw4Foss { dimension "variant" applicationId "org.eehouse.android.xw4" manifestPlaceholders = [ APP_ID: applicationId ] resValue "string", "app_name", "CrossWords" resValue "string", "nbs_port", "3344" buildConfigField "boolean", "WIDIR_ENABLED", "false" buildConfigField "String", "VARIANT_NAME", "\"FOSS\"" buildConfigField "int", "VARIANT_CODE", "5" buildConfigField "String", "NFC_AID", "\"${NFC_AID_XW4}\"" resValue "string", "nfc_aid", "$NFC_AID_XW4" externalNativeBuild.ndkBuild.cFlags += ['-DVARIANT_xw4Foss'] externalNativeBuild.ndkBuild.arguments += ['XW_BT_UUID=' + XW_UUID] } // WARNING: "all" breaks things. Seems to be a keyword. Need // to figure out how to express include-all-abis // all { // dimension "abi" // versionCode 0 + VERSION_CODE_BASE // } // armeabi { // dimension "abi" // versionCode 1 + VERSION_CODE_BASE // } // x86 { // dimension "abi" // versionCode 2 + VERSION_CODE_BASE // } // armeabiv7a { // dimension "abi" // versionCode 3 + VERSION_CODE_BASE // } all { buildConfigField "String", "compileSdkVersion", "\"$compileSdkVersion\"" } } signingConfigs { debug { def path = System.getenv("DEBUG_KEYSTORE_PATH") if (! path) { path = "./debug.keystore" } storeFile file(path) keyAlias "androiddebugkey" storePassword "android" keyPassword "android" } } buildTypes { all { externalNativeBuild { ndkBuild.arguments += ["INITIAL_CLIENT_VERS=" + INITIAL_CLIENT_VERS] } } release { debuggable false minifyEnabled false // PENDING // proguard crashes when I do this (the optimize part) // proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' resValue "bool", "DEBUG", "false" externalNativeBuild { ndkBuild { arguments += ['BUILD_TARGET=release'] } } ndk { abiFilters 'armeabi-v7a', 'arm64-v8a' } } debug { debuggable true resValue "bool", "DEBUG", "true" // Drop this. Takes too long to build // minifyEnabled true // for testing proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' // This doesn't work on marshmallow: duplicate permission error // applicationIdSuffix ".debug" externalNativeBuild { ndkBuild { cFlags += ['-DDEBUG'] arguments += ['BUILD_TARGET=debug'] } } ndk { abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' } } } externalNativeBuild { ndkBuild { path "../jni/Android.mk" } } 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. xw4GPlay { release { jniLibs.srcDir "../libs-xw4GPlayRelease" } debug { jniLibs.srcDir "../libs-xw4GPlayDebug" } } xw4d { release { jniLibs.srcDir "../libs-xw4dRelease" } debug { jniLibs.srcDir "../libs-xw4dDebug" } } xw4dGPlay { release { jniLibs.srcDir "../libs-xw4dGPlayRelease" } debug { jniLibs.srcDir "../libs-xw4dGPlayDebug" } } xw4Foss { release { jniLibs.srcDir "../libs-xw4FossRelease" } debug { jniLibs.srcDir "../libs-xw4FossDebug" } } xw4fdroid { release { jniLibs.srcDir "../libs-xw4fdroidRelease" } debug { jniLibs.srcDir "../libs-xw4fdroidDebug" } } } lintOptions { abortOnError false } applicationVariants.all { variant -> variant.outputs.each { output -> def newName = output.outputFile.name newName = newName.replace(".apk","-${GITREV}.apk") newName = newName.replace("app-","") output.outputFileName = newName } } } dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.+' implementation 'androidx.core:core:1.0.+' implementation 'androidx.preference:preference:1.2.+' implementation 'androidx.lifecycle:lifecycle-extensions:2.0.+' annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.0.+' // 3:1.2.+ crashes on API 18 and below (all Jelly Beans) because // java.nio.charset.StandardCharsets not defined. Does not crash on // 19 (KitKat). if ( USE_KITKAT_MQTT ) { // Most recent seems to be 1.2.5 tagged July 2020. // https://github.com/eclipse/paho.mqtt.java/tags implementation "org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.+" } else { implementation "org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.+" } // Try this if paho keeps sucking (and it's not my fault) // implementation("com.hivemq:hivemq-mqtt-client:1.3.0") implementation 'com.google.zxing:core:3.3.+' implementation 'com.jakewharton:process-phoenix:2.1.2' } task mkImages(type: Exec) { workingDir '../' commandLine './scripts/mkimages.sh' } task copyLocStrings(type: Exec) { workingDir '../' commandLine 'make', '-f', './scripts/copy-strings.mk' } task mkPrefsWrapper(type: Exec) { workingDir '../' commandLine 'make', '-f', './scripts/prefsWrapper.mk' } task cleanPrefsWrapper(type: Exec) { workingDir '../' commandLine 'make', '-f', './scripts/prefsWrapper.mk', 'clean' } task cleanLocStrings(type: Exec) { workingDir '../' commandLine 'make', '-f', './scripts/copy-strings.mk', 'clean' } clean.dependsOn cleanLocStrings, cleanPrefsWrapper task myPreBuild(dependsOn: ['mkImages', 'copyLocStrings', 'mkPrefsWrapper', 'copyStringsXw4D', 'copyStringsXw4DGPlay']) { } preBuild.dependsOn myPreBuild task copyStringsXw4D(type: Exec) { workingDir './' environment.put('APPNAME', 'CrossDbg') commandLine 'make', '-f', '../scripts/Variant.mk', "src/xw4d/res/values/strings.xml" } task copyStringsXw4DGPlay(type: Exec) { workingDir './' environment.put('APPNAME', 'CrossDbg') commandLine 'make', '-f', '../scripts/Variant.mk', "src/xw4dGPlay/res/values/strings.xml" } task makeBuildAssets() { def assetsDir = android.sourceSets.main.assets.srcDirs.toArray()[0] String path = new File(assetsDir, BUILD_INFO_NAME).getAbsolutePath() String out = "git_describe: ${GITREV}\n" String HEAD = "git rev-parse HEAD".execute().text.trim() out += "HEAD: ${HEAD}\n" String date = "date".execute().text.trim() out += "date: ${date}\n" // I want the variant, but that's harder. Here's a quick hack from SO. // String target = gradle.startParameter.taskNames[0] // out += "target: ${target}\n" String diff = "git diff".execute().text.trim() if (diff) { out += "\n" + diff } new File(path).write(out) // Now the latest commit path = new File(assetsDir, LAST_COMMIT_FILE).getAbsolutePath() out = "git log -n 1".execute().text.trim() new File(path).write(out) } gradle.projectsEvaluated { build.dependsOn(makeBuildAssets) } // To turn on javac options // tasks.withType(JavaCompile) { // options.compilerArgs += ["-Xdiags:verbose"] // }