Gadgetbridge/app/build.gradle

370 lines
15 KiB
Groovy
Raw Normal View History

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
2015-01-07 14:00:18 +01:00
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()
}
2022-01-27 18:00:22 +01:00
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
}
}
2016-03-17 23:41:41 +01:00
2021-12-30 08:21:37 +01:00
def getGitHashShort = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
} catch (ignored){
return null
}
}
2015-01-07 14:00:18 +01:00
android {
compileOptions {
2022-09-09 19:58:34 +02:00
// for Android 5+
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Bangle.js: Bump flavor targetSdkVersion to 31 This also touches parts of the app not only used for bangle.js. E.g. pending intents gets new flags from SDK 23 inclusive. Bluetooth permissions are updated to work on SDK 31. Permission handling is updated to the new way for doing it with introduction of a new function. This is called for newer sdk versions. bump Bangle.js flavor targetSdkVersion to 31 update comments re SDK 31 set the 'exported=true' I introduced to false instead - except for three places add uses-permission for handling bluetooth in order to work on api >30 add if-blocks adding FLAG_IMMUTABLE to PendingIntents on api >30 add link to bluetooth documentation Add comment to banglejs manifest. Add requirement annotation to ControlCenterv bump compileSdkVersion to 31 add "OpenAppSettings" permission popup while working out individual permission popups on android 13 if SDK < 31 do permissions one by one, else send user to app info page to switch permissions manually working solution, but needs cleaning do some cleaning, not done though remove some logging remove import Log tweak and remove toasts in new permissions handling Change conditions `> Build.VERSION_CODES.Q` to `>= Build.VERSION_CODES.R` matching the style used everywhere else Revert "Change conditions `> Build.VERSION_CODES.Q` to `>= Build.VERSION_CODES.R` matching the style used everywhere else" This reverts commit 2929629ff43fbb685eb3d15e42459f321f68fa11. Revert "add if-blocks adding FLAG_IMMUTABLE to PendingIntents on api >30" This reverts commit ed8e1df7bb8b71fee745fbf9d10747d47c8f6cb8. Pending intents gets `PendingIntent.FLAG_IMMUTABLE` if `(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)`. Bangle.js: undo `@RequiresApi` code R ... to remove error in Android Studio where declared required api was higher then minSDK version. Use FLAG_MUTABLE for reply to test notification This should fix Gadgetbridge crashing when replying to the test notification from the debug activity. As reported here: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/2924#issuecomment-917282 Change to use FLAG_IMMUTABLE/_MUTABLE from SDK 23 ... as suggested by Android Studio. This is supposed to make the app more secure by not allowing certain changes to pending intents where they are not expected. If I understood correctly. Add PendingIntentUtils class to manage mutability
2022-10-09 14:53:04 +02:00
compileSdkVersion 31
buildToolsVersion "31.0.0"
2015-01-07 14:00:18 +01:00
defaultConfig {
applicationId "nodomain.freeyourgadget.gadgetbridge"
2022-09-09 19:58:34 +02:00
minSdkVersion 21
2023-07-02 18:55:52 +02:00
targetSdkVersion 31
2015-12-07 18:10:00 +01:00
// Note: always bump BOTH versionCode and versionName!
2023-07-07 20:00:57 +02:00
versionName "0.75.1"
versionCode 224
vectorDrawables.useSupportLibrary = true
2021-12-30 08:21:37 +01:00
buildConfigField "String", "GIT_HASH_SHORT", "\"${getGitHashShort()}\""
2022-03-31 11:36:26 +02:00
buildConfigField "boolean", "INTERNET_ACCESS", "false"
2022-01-27 18:00:22 +01:00
resValue "string", "pebble_content_provider", "com.getpebble.android.provider"
resValue "string", "app_name", "@string/application_name_generic"
resValue "string", "title_activity_controlcenter", "@string/title_activity_controlcenter_generic"
resValue "string", "about_activity_title", "@string/about_activity_title_generic"
resValue "string", "about_description", "@string/about_description_generic"
resValue "string", "gadgetbridge_running", "@string/gadgetbridge_running_generic"
2022-01-27 18:00:22 +01:00
}
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")
}
}
2015-01-07 14:00:18 +01:00
}
2022-08-10 22:16:32 +02:00
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.bangle.provider"
resValue "string", "app_name", "@string/application_name_banglejs_main"
resValue "string", "title_activity_controlcenter", "@string/title_activity_controlcenter_banglejs_main"
resValue "string", "about_activity_title", "@string/about_activity_title_banglejs_main"
resValue "string", "about_description", "@string/about_description_banglejs_main"
resValue "string", "gadgetbridge_running", "@string/gadgetbridge_running_banglejs_main"
Bangle.js: Bump flavor targetSdkVersion to 31 This also touches parts of the app not only used for bangle.js. E.g. pending intents gets new flags from SDK 23 inclusive. Bluetooth permissions are updated to work on SDK 31. Permission handling is updated to the new way for doing it with introduction of a new function. This is called for newer sdk versions. bump Bangle.js flavor targetSdkVersion to 31 update comments re SDK 31 set the 'exported=true' I introduced to false instead - except for three places add uses-permission for handling bluetooth in order to work on api >30 add if-blocks adding FLAG_IMMUTABLE to PendingIntents on api >30 add link to bluetooth documentation Add comment to banglejs manifest. Add requirement annotation to ControlCenterv bump compileSdkVersion to 31 add "OpenAppSettings" permission popup while working out individual permission popups on android 13 if SDK < 31 do permissions one by one, else send user to app info page to switch permissions manually working solution, but needs cleaning do some cleaning, not done though remove some logging remove import Log tweak and remove toasts in new permissions handling Change conditions `> Build.VERSION_CODES.Q` to `>= Build.VERSION_CODES.R` matching the style used everywhere else Revert "Change conditions `> Build.VERSION_CODES.Q` to `>= Build.VERSION_CODES.R` matching the style used everywhere else" This reverts commit 2929629ff43fbb685eb3d15e42459f321f68fa11. Revert "add if-blocks adding FLAG_IMMUTABLE to PendingIntents on api >30" This reverts commit ed8e1df7bb8b71fee745fbf9d10747d47c8f6cb8. Pending intents gets `PendingIntent.FLAG_IMMUTABLE` if `(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)`. Bangle.js: undo `@RequiresApi` code R ... to remove error in Android Studio where declared required api was higher then minSDK version. Use FLAG_MUTABLE for reply to test notification This should fix Gadgetbridge crashing when replying to the test notification from the debug activity. As reported here: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/2924#issuecomment-917282 Change to use FLAG_IMMUTABLE/_MUTABLE from SDK 23 ... as suggested by Android Studio. This is supposed to make the app more secure by not allowing certain changes to pending intents where they are not expected. If I understood correctly. Add PendingIntentUtils class to manage mutability
2022-10-09 14:53:04 +02:00
targetSdkVersion 31 // Bangle.js flavor only - We need SDK 31 for updates pushed to Play Store from 2022-11-01
// Note: app/src/banglejs/AndroidManifest.xml contains some extra permissions we need to make SDK 30 and up work
2022-08-10 22:16:32 +02:00
}
}
2015-01-07 14:00:18 +01:00
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
2022-01-27 18:00:22 +01:00
resValue "string", "pebble_content_provider", "com.getpebble.android.provider"
2015-01-07 14:00:18 +01:00
}
2022-01-27 18:00:22 +01:00
nightly {
applicationIdSuffix ".nightly"
versionNameSuffix "-${getGitHashShort}"
minifyEnabled true
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
resValue "string", "pebble_content_provider", "com.getpebble.android.provider"
resValue "string", "app_name", "@string/application_name_main_nightly"
resValue "string", "title_activity_controlcenter", "@string/title_activity_controlcenter_main_nightly"
resValue "string", "about_activity_title", "@string/about_activity_title_main_nightly"
resValue "string", "about_description", "@string/about_description_main_nightly"
resValue "string", "gadgetbridge_running", "@string/gadgetbridge_running_main_nightly"
2022-08-10 22:16:32 +02:00
2022-01-27 18:00:22 +01:00
debuggable true
2022-08-10 22:16:32 +02:00
if (System.getProperty("nightly_store_file") != null) {
signingConfig signingConfigs.nightly
//this was conflicting with regular debug type (it should not), so it is only available for CI builds:
productFlavors.main.resValue "string", "pebble_content_provider", "com.getpebble.android.provider"
productFlavors.main.resValue "string", "app_name", "@string/application_name_main_nightly"
productFlavors.main.resValue "string", "title_activity_controlcenter", "@string/title_activity_controlcenter_main_nightly"
productFlavors.main.resValue "string", "about_activity_title", "@string/about_activity_title_main_nightly"
productFlavors.main.resValue "string", "about_description", "@string/about_description_main_nightly"
productFlavors.main.resValue "string", "gadgetbridge_running", "@string/gadgetbridge_running_main_nightly"
//keep the pebble provider for people who want this. In case of need we can create Banglejs Nopebble
productFlavors.banglejs.resValue "string", "pebble_content_provider", "com.getpebble.android.provider"
productFlavors.banglejs.resValue "string", "app_name", "@string/application_name_banglejs_nightly"
productFlavors.banglejs.resValue "string", "title_activity_controlcenter", "@string/title_activity_controlcenter_banglejs_nightly"
productFlavors.banglejs.resValue "string", "about_activity_title", "@string/about_activity_title_banglejs_nightly"
productFlavors.banglejs.resValue "string", "about_description", "@string/about_description_banglejs_nightly"
productFlavors.banglejs.resValue "string", "gadgetbridge_running", "@string/gadgetbridge_running_banglejs_nightly"
} else {
signingConfig signingConfigs.debug
}
2022-01-27 18:00:22 +01:00
}
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"
resValue "string", "app_name", "@string/application_name_main_nopebble"
resValue "string", "title_activity_controlcenter", "@string/title_activity_controlcenter_main_nopebble"
resValue "string", "about_activity_title", "@string/about_activity_title_main_nopebble"
resValue "string", "about_description", "@string/about_description_main_nopebble"
resValue "string", "gadgetbridge_running", "@string/gadgetbridge_running_main_nopebble"
2022-01-27 18:00:22 +01:00
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"
}
}
}
2015-01-07 14:00:18 +01:00
}
2022-03-31 11:36:26 +02:00
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 {
2018-03-22 21:01:59 +01:00
unitTests {
returnDefaultValues = true
includeAndroidResources = true
}
}
2015-01-07 14:00:18 +01:00
}
pmd {
toolVersion = "5.5.5"
}
2015-01-07 14:00:18 +01:00
dependencies {
// testImplementation "ch.qos.logback:logback-classic:1.1.3"
// testImplementation "ch.qos.logback:logback-core:1.1.3"
2020-11-05 12:16:34 +01:00
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
2022-09-10 22:38:57 +02:00
testImplementation "junit:junit:4.13.2"
testImplementation "org.mockito:mockito-core:1.10.19"
2022-09-10 22:38:57 +02:00
testImplementation "org.robolectric:robolectric:4.8.2"
testImplementation "org.hamcrest:hamcrest-library:1.3"
testImplementation "com.google.code.gson:gson:2.8.8"
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "androidx.appcompat:appcompat:1.4.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.palette:palette:1.0.0"
implementation "androidx.activity:activity:1.5.1"
implementation "androidx.fragment:fragment:1.4.1"
implementation "com.google.android.material:material:1.6.1"
implementation 'com.google.android.flexbox:flexbox:3.0.0'
implementation "com.google.code.gson:gson:2.8.8"
implementation "no.nordicsemi.android:dfu:1.12.0"
2022-08-07 21:51:48 +02:00
implementation("com.github.tony19:logback-android:2.0.0") {
exclude group: "com.google.android", module: "android"
}
2022-08-07 21:51:48 +02:00
implementation "org.slf4j:slf4j-api:1.7.36"
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"
2022-09-19 21:45:58 +02:00
implementation "co.nstant.in:cbor: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"
2019-05-23 22:02:25 +02:00
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-javalite:3.10.0'
2022-03-31 11:36:26 +02:00
implementation 'com.android.volley:volley:1.2.1'
// NON-FOSS dependencies
// implementation('androidx.core:core-google-shortcuts:1.0.1') {
// exclude group:'com.google.android.gms'
// exclude group:'com.google.firebase'
// }
// JSR-310 timezones backport for Android, since we're still API 21
implementation 'com.jakewharton.threetenabp:threetenabp:1.4.0'
testImplementation 'org.threeten:threetenbp:1.6.0'
2022-08-18 23:03:28 +02:00
// Android SDK bundles org.json, but we need an actual implementation to replace the stubs in tests
testImplementation 'org.json:json:20180813'
2016-03-27 22:13:06 +02:00
}
preBuild.dependsOn(":GBDaoGenerator:genSources")
2016-03-27 22:13:06 +02:00
gradle.beforeProject {
preBuild.dependsOn(":GBDaoGenerator:genSources")
2015-01-07 14:00:18 +01:00
}
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 {
2019-05-23 22:02:25 +02:00
destination file("$project.buildDir/reports/pmd/pmd.xml")
}
html {
2019-05-23 22:02:25 +02:00
destination file("$project.buildDir/reports/pmd/pmd.html")
}
}
}
sourceSets {
main {
main.java.srcDirs += "${protobuf.generatedFilesBaseDir}"
main.java.srcDirs += "build/generated/source/buildConfig"
}
}
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")
}
}
}
2022-09-18 13:19:23 +02:00
task cleanGenerated(type: Delete) {
delete fileTree('src/main/java/nodomain/freeyourgadget/gadgetbridge/entities') {
include '**/*.java'
exclude '**/Abstract*.java'
}
}
tasks.clean.dependsOn(tasks.cleanGenerated)
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.10.0'
}
generateProtoTasks {
all().each { task ->
task.builtins {
2022-09-18 13:19:23 +02:00
java {
option 'lite'
}
}
}
}
}