mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-07-03 11:33:19 +02:00
This PR adds build flavors to `build.gradle`. The default is called `main`, but we also add `banglejs` which allows the building of an app called `Bangle.js Gadgetbridge`. This will have internet connectivity, allowing Bangle.js watches to request data directly from the internet - and it's named so as hopefully not to be confused with the normal offline Gadgetbridge, while still giving credit. Eventually the plan is to put this on the Google Play store, and to have additions in it which are good for Bangle.js users but would otherwise negatively impact normal Gadgetbridge users (a build flavor is used so we can keep the same codebase and not fork). About naming - I'd mentioned `Gadgetbridge for Bangle` to @ashimokawa but thinking about how it would appear in the app store and Android apps list, it probably makes sense to call it `Bangle.js Gadgetbridge` so it's listed under `B...`. Happy to change or use something else if you have strong opinions though. **Note:** adding build flavors seems to add the flavor name to existing builds. As a result, *all other builds will now have `main` in the name*. Unfortunately I didn't see another way around this, but hopefully it won't break anything. Co-authored-by: Gordon Williams <gw@pur3.co.uk> Reviewed-on: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/2621 Co-authored-by: gfwilliams <gfwilliams@noreply.codeberg.org> Co-committed-by: gfwilliams <gfwilliams@noreply.codeberg.org>
322 lines
11 KiB
Groovy
322 lines
11 KiB
Groovy
import com.github.spotbugs.SpotBugsTask
|
|
|
|
import java.nio.file.Files
|
|
|
|
apply plugin: "com.android.application"
|
|
apply plugin: "com.github.spotbugs"
|
|
apply plugin: "pmd"
|
|
apply plugin: 'com.google.protobuf'
|
|
|
|
def ABORT_ON_CHECK_FAILURE = false
|
|
|
|
tasks.withType(Test) {
|
|
systemProperty "MiFirmwareDir", System.getProperty("MiFirmwareDir", null)
|
|
systemProperty "logback.configurationFile", System.getProperty("user.dir", null) + "/app/src/main/assets/logback.xml"
|
|
systemProperty "GB_LOGFILES_DIR", Files.createTempDirectory("gblog").toString()
|
|
}
|
|
def getVersionCode = { ->
|
|
try {
|
|
def stdout = new ByteArrayOutputStream()
|
|
exec {
|
|
commandLine 'git', 'rev-list', 'HEAD', '--count'
|
|
standardOutput = stdout
|
|
}
|
|
return Integer.valueOf(stdout.toString().trim())
|
|
} catch (ignored) {
|
|
return null
|
|
}
|
|
}
|
|
|
|
def getGitHashShort = { ->
|
|
try {
|
|
def stdout = new ByteArrayOutputStream()
|
|
exec {
|
|
commandLine 'git', 'rev-parse', '--short', 'HEAD'
|
|
standardOutput = stdout
|
|
}
|
|
return stdout.toString().trim()
|
|
} catch (ignored){
|
|
return null
|
|
}
|
|
}
|
|
|
|
android {
|
|
compileOptions {
|
|
// for KitKat
|
|
sourceCompatibility JavaVersion.VERSION_1_7
|
|
targetCompatibility JavaVersion.VERSION_1_7
|
|
}
|
|
compileSdkVersion 29
|
|
|
|
defaultConfig {
|
|
applicationId "nodomain.freeyourgadget.gadgetbridge"
|
|
minSdkVersion 19
|
|
targetSdkVersion 29
|
|
multiDexEnabled true
|
|
|
|
// Note: always bump BOTH versionCode and versionName!
|
|
versionName "0.66.0"
|
|
versionCode 210
|
|
vectorDrawables.useSupportLibrary = true
|
|
multiDexEnabled true
|
|
buildConfigField "String", "GIT_HASH_SHORT", "\"${getGitHashShort()}\""
|
|
buildConfigField "boolean", "INTERNET_ACCESS", "false"
|
|
resValue "string", "pebble_content_provider", "com.getpebble.android.provider"
|
|
}
|
|
signingConfigs {
|
|
nightly {
|
|
if (System.getProperty("nightly_store_file") != null) {
|
|
storeFile file(System.getProperty("nightly_store_file"))
|
|
storePassword System.getProperty("nightly_store_password")
|
|
keyAlias System.getProperty("nightly_key_alias")
|
|
keyPassword System.getProperty("nightly_key_password")
|
|
}
|
|
}
|
|
}
|
|
buildTypes {
|
|
release {
|
|
minifyEnabled true
|
|
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
|
|
resValue "string", "pebble_content_provider", "com.getpebble.android.provider"
|
|
}
|
|
|
|
nightly {
|
|
applicationIdSuffix ".nightly"
|
|
versionNameSuffix "-${getGitHashShort}"
|
|
minifyEnabled true
|
|
if (System.getProperty("nightly_store_file") != null) {
|
|
signingConfig signingConfigs.nightly
|
|
} else {
|
|
signingConfig signingConfigs.debug
|
|
}
|
|
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
|
|
resValue "string", "pebble_content_provider", "com.getpebble.android.provider"
|
|
debuggable true
|
|
}
|
|
nopebble {
|
|
applicationIdSuffix ".nightly_nopebble"
|
|
versionNameSuffix "-${getGitHashShort}"
|
|
minifyEnabled true
|
|
if (System.getProperty("nightly_store_file") != null) {
|
|
signingConfig signingConfigs.nightly
|
|
} else {
|
|
signingConfig signingConfigs.debug
|
|
}
|
|
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
|
|
resValue "string", "pebble_content_provider", "com.getpebble.android.nopebble.provider"
|
|
debuggable true
|
|
}
|
|
|
|
applicationVariants.all { variant ->
|
|
variant.resValue "string", "applicationId", variant.applicationId
|
|
|
|
if (variant.buildType.name == 'nightly' || variant.buildType.name == 'nopebble') {
|
|
variant.outputs.all {
|
|
setVersionCodeOverride(getVersionCode())
|
|
//setVersionNameOverride(getGitHashShort())
|
|
setVersionNameOverride(variant.versionName)
|
|
outputFileName = "${applicationId}_${variant.versionName}.apk"
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
flavorDimensions "device_type"
|
|
productFlavors {
|
|
main {
|
|
// Ensure that when starting from scratch, 'main' is selected, not 'banglejs'
|
|
getIsDefault().set(true)
|
|
// the default build product flavor
|
|
dimension "device_type"
|
|
//applicationIdSuffix ""
|
|
//versionNameSuffix ""
|
|
}
|
|
banglejs {
|
|
dimension "device_type"
|
|
applicationId "com.espruino.gadgetbridge"
|
|
applicationIdSuffix ".banglejs"
|
|
versionNameSuffix "-banglejs"
|
|
buildConfigField "boolean", "INTERNET_ACCESS", "true"
|
|
// Disable pebble provider to allow Bangle.js Gadgetbridge to coexist with Gadgetbridge
|
|
resValue "string", "pebble_content_provider", "com.getpebble.android.nopebble.provider"
|
|
}
|
|
}
|
|
|
|
lintOptions {
|
|
abortOnError ABORT_ON_CHECK_FAILURE
|
|
lintConfig file("${project.rootDir}/config/lint/lint.xml")
|
|
// If true, generate an HTML report (with issue explanations, sourcecode, etc)
|
|
htmlReport true
|
|
// Optional path to report (default will be lint-results.html in the builddir)
|
|
htmlOutput file("$project.buildDir/reports/lint/lint.html")
|
|
}
|
|
|
|
testOptions {
|
|
unitTests {
|
|
returnDefaultValues = true
|
|
includeAndroidResources = true
|
|
}
|
|
}
|
|
externalNativeBuild {
|
|
cmake {
|
|
path "src/main/c/CMakeLists.txt"
|
|
version "3.10.2"
|
|
}
|
|
}
|
|
sourceSets {
|
|
main {
|
|
jniLibs.srcDirs = ['libs'] // where libs is the name of the directory!
|
|
}
|
|
}
|
|
}
|
|
|
|
pmd {
|
|
toolVersion = "5.5.5"
|
|
}
|
|
|
|
dependencies {
|
|
// testImplementation "ch.qos.logback:logback-classic:1.1.3"
|
|
// testImplementation "ch.qos.logback:logback-core:1.1.3"
|
|
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
|
|
testImplementation "junit:junit:4.12"
|
|
testImplementation "org.mockito:mockito-core:1.10.19"
|
|
testImplementation "org.robolectric:robolectric:4.2.1"
|
|
testImplementation "com.google.code.gson:gson:2.8.6"
|
|
|
|
implementation fileTree(dir: "libs", include: ["*.jar"])
|
|
implementation "androidx.appcompat:appcompat:1.3.1"
|
|
implementation "androidx.preference:preference:1.1.1"
|
|
implementation "androidx.cardview:cardview:1.0.0"
|
|
implementation "androidx.recyclerview:recyclerview:1.2.1"
|
|
implementation "androidx.legacy:legacy-support-v4:1.0.0"
|
|
implementation "androidx.gridlayout:gridlayout:1.0.0"
|
|
implementation "androidx.multidex:multidex:2.0.1"
|
|
implementation "androidx.palette:palette:1.0.0"
|
|
|
|
implementation "com.google.android.material:material:1.4.0"
|
|
implementation 'com.google.android.flexbox:flexbox:3.0.0'
|
|
implementation "com.google.code.gson:gson:2.8.6"
|
|
|
|
implementation "no.nordicsemi.android:dfu:1.11.1"
|
|
implementation("com.github.tony19:logback-android-classic:1.1.1-6") {
|
|
exclude group: "com.google.android", module: "android"
|
|
}
|
|
implementation "org.slf4j:slf4j-api:1.7.24"
|
|
implementation "com.github.PhilJay:MPAndroidChart:v3.1.0"
|
|
implementation "com.github.pfichtner:durationformatter:0.1.1"
|
|
implementation "de.cketti.library.changelog:ckchangelog:1.2.2"
|
|
implementation "net.e175.klaus:solarpositioning:0.0.9"
|
|
// use pristine greendao instead of our custom version, since our custom jitpack-packaged
|
|
// version contains way too much and our custom patches are in the generator only.
|
|
implementation "org.greenrobot:greendao:2.2.1"
|
|
implementation "org.apache.commons:commons-lang3:3.7"
|
|
implementation "org.cyanogenmod:platform.sdk:6.0"
|
|
implementation 'com.jaredrummler:colorpicker:1.0.2'
|
|
// implementation project(":DaoCore")
|
|
implementation 'com.github.wax911:android-emojify:0.1.7'
|
|
implementation 'com.google.protobuf:protobuf-lite:3.0.1'
|
|
implementation "androidx.multidex:multidex:2.0.1"
|
|
implementation 'com.android.volley:volley:1.2.1'
|
|
}
|
|
|
|
preBuild.dependsOn(":GBDaoGenerator:genSources")
|
|
|
|
gradle.beforeProject {
|
|
preBuild.dependsOn(":GBDaoGenerator:genSources")
|
|
}
|
|
|
|
check.dependsOn "spotbugsMain", "pmd", "lint"
|
|
|
|
task pmd(type: Pmd) {
|
|
ruleSetFiles = files("${project.rootDir}/config/pmd/pmd-ruleset.xml")
|
|
ignoreFailures = !ABORT_ON_CHECK_FAILURE
|
|
ruleSets = [
|
|
"java-android",
|
|
"java-basic",
|
|
"java-braces",
|
|
"java-clone",
|
|
"java-codesize",
|
|
"java-controversial",
|
|
"java-coupling",
|
|
"java-design",
|
|
"java-empty",
|
|
"java-finalizers",
|
|
"java-imports",
|
|
"java-junit",
|
|
"java-optimizations",
|
|
"java-strictexception",
|
|
"java-strings",
|
|
"java-sunsecure",
|
|
"java-typeresolution",
|
|
"java-unnecessary",
|
|
"java-unusedcode"
|
|
]
|
|
|
|
source "src"
|
|
include "**/*.java"
|
|
exclude "**/gen/**"
|
|
|
|
reports {
|
|
xml.enabled = false
|
|
html.enabled = true
|
|
xml {
|
|
destination file("$project.buildDir/reports/pmd/pmd.xml")
|
|
}
|
|
html {
|
|
destination file("$project.buildDir/reports/pmd/pmd.html")
|
|
}
|
|
}
|
|
}
|
|
|
|
// this is just for spotbugs to let the plugin create the task
|
|
sourceSets {
|
|
main {
|
|
main.java.srcDirs += "${protobuf.generatedFilesBaseDir}/main/javalite"
|
|
}
|
|
}
|
|
|
|
spotbugs {
|
|
toolVersion = "3.1.12"
|
|
ignoreFailures = !ABORT_ON_CHECK_FAILURE
|
|
effort = "default"
|
|
reportLevel = "medium"
|
|
}
|
|
|
|
tasks.withType(SpotBugsTask) {
|
|
source = fileTree('src/main/java')
|
|
classes = files("${project.rootDir}/app/build/intermediates/javac/debug/classes")
|
|
excludeFilter = new File("${project.rootDir}/config/findbugs/findbugs-filter.xml")
|
|
reports {
|
|
xml.enabled = false
|
|
html.enabled = true
|
|
xml {
|
|
destination file ("$project.buildDir/reports/spotbugs/spotbugs-output.xml")
|
|
}
|
|
html {
|
|
destination file ("$project.buildDir/reports/spotbugs/spotbugs-output.html")
|
|
}
|
|
}
|
|
}
|
|
|
|
protobuf {
|
|
protoc {
|
|
artifact = 'com.google.protobuf:protoc:3.0.0'
|
|
}
|
|
plugins {
|
|
javalite {
|
|
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
|
|
}
|
|
}
|
|
generateProtoTasks {
|
|
all().each { task ->
|
|
task.builtins {
|
|
remove java
|
|
}
|
|
task.plugins {
|
|
javalite { }
|
|
}
|
|
}
|
|
}
|
|
}
|