xwords/xwords4/android/app/build.gradle
Eric House e6c5e2cf04 getting ready for first of two quick releases
Two branches doesn't work because they can't have the same
tag. Duh. I'll do two releases, and two tags, complete with version
code change, to support pre-Kitkat and everybody else.
2022-04-25 11:47:36 -07:00

468 lines
17 KiB
Groovy

/* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */
/*
* Copyright 2015 - 2021 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 = 182
def VERSION_NAME = '4.4.185'
def BUILD_INFO_NAME = "build-info.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 HAS_CURRENT_MQTT changed to false, and then
// immediately after one with it set to true.
def HAS_CURRENT_MQTT = false
if ( HAS_CURRENT_MQTT ) {
VERSION_CODE_BASE += 1;
}
// 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"
boolean forFDroid = hasProperty('forFDroid')
// 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 {
// 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 ( HAS_CURRENT_MQTT ) {
minSdkVersion 19 // Required for paho client > 3:1.1.+
} else {
minSdkVersion 14
}
targetSdkVersion 30 // must match ../build.gradle
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 {
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 "String", "KEY_FCMID", "\"FBMService_fcmid\""
buildConfigField "boolean", "ATTACH_SUPPORTED", "false"
buildConfigField "boolean", "OFFER_MQTT", "true"
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"
}
xw4GPlay {
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", "\"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]
buildConfigField "String", "KEY_FCMID", "null"
}
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", "KEY_FCMID", "null"
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", "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 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
// }
}
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.0'
implementation 'androidx.core:core:1.0.0'
implementation 'androidx.preference:preference:1.1.+'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.0.0'
implementation 'com.google.firebase:firebase-messaging:17.3.4' // rm-for-fdroid
implementation 'com.google.firebase:firebase-core:16.0.6' // rm-for-fdroid
implementation 'com.github.eehouse:nbsproxy:v0.2.2'
// 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 ( HAS_CURRENT_MQTT ) {
implementation "org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.+"
} else {
implementation "org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.+"
}
implementation 'com.google.zxing:core:3.3.+'
}
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)
}
gradle.projectsEvaluated {
build.dependsOn(makeBuildAssets)
}
// To turn on javac options
// tasks.withType(JavaCompile) {
// options.compilerArgs += ["-Xdiags:verbose"]
// }