1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-24 19:06:53 +01:00
Gadgetbridge/app/build.gradle

390 lines
13 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 = true
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()
}
2023-08-09 20:52:03 +02:00
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
2023-08-09 20:52:03 +02:00
def buildGitChangelog = {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'log', '--pretty=format:%h %s'
standardOutput = stdout
}
def commitVersionCode = getVersionCode()
def includedCommits = 0
2023-08-09 20:52:03 +02:00
def changelogNode = new Node(null, 'changelog')
stdout.toString().trim().eachLine { line ->
if (includedCommits > 100) {
return true;
}
2023-08-09 20:52:03 +02:00
def (commitHash, commitMessage) = line.split(" ", 2)
if (commitMessage.contains("Translated using Weblate")) {
return true;
}
2023-08-09 20:52:03 +02:00
def releaseNode = new Node(changelogNode, 'release', [version: commitHash, versioncode: commitVersionCode--])
def _ = new Node(releaseNode, 'change', [:], commitMessage)
includedCommits++
2023-08-09 20:52:03 +02:00
}
def changelogFile = new File("${project.rootDir}/app/build/generated/res/changelog/xml/changelog_git.xml")
changelogFile.getParentFile().mkdirs()
changelogFile.write(groovy.xml.XmlUtil.serialize(changelogNode))
}
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) {
2021-12-30 08:21:37 +01:00
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
}
namespace 'nodomain.freeyourgadget.gadgetbridge'
2015-01-07 14:00:18 +01:00
defaultConfig {
applicationId "nodomain.freeyourgadget.gadgetbridge"
//noinspection OldTargetApi
2023-06-02 17:57:44 +02:00
targetSdkVersion 33
compileSdk 33
minSdkVersion 21
2015-12-07 18:10:00 +01:00
// Note: always bump BOTH versionCode and versionName!
2024-03-25 09:46:40 +01:00
versionName "0.80.0"
versionCode 231
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
}
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 {
mainline {
// Ensure that when starting from scratch, 'mainline' is selected, not 'banglejs'
2022-08-10 22:16:32 +02:00
getIsDefault().set(true)
// the default build product flavor
dimension "device_type"
//applicationIdSuffix ""
//versionNameSuffix ""
}
2022-08-10 22:16:32 +02:00
banglejs {
dimension "device_type"
applicationId "com.espruino.gadgetbridge"
applicationIdSuffix ".banglejs"
versionNameSuffix "-banglejs"
buildConfigField "boolean", "INTERNET_ACCESS", "true"
2023-06-02 17:57:44 +02:00
targetSdkVersion 33
// Note: app/src/banglejs/AndroidManifest.xml contains some extra permissions
2022-08-10 22:16:32 +02:00
}
}
2023-08-09 20:52:03 +02:00
sourceSets {
main {
res.srcDirs += "build/generated/res/changelog"
}
}
2015-01-07 14:00:18 +01:00
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
2015-01-07 14:00:18 +01:00
}
2022-01-27 18:00:22 +01:00
nightly {
applicationIdSuffix ".nightly"
versionNameSuffix "-${getGitHashShort}"
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
minifyEnabled true
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
} else {
signingConfig signingConfigs.debug
}
2022-01-27 18:00:22 +01:00
}
2022-01-27 18:00:22 +01:00
nopebble {
applicationIdSuffix ".nightly_nopebble"
versionNameSuffix "-${getGitHashShort}"
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
2022-01-27 18:00:22 +01:00
minifyEnabled true
debuggable true
2022-01-27 18:00:22 +01:00
if (System.getProperty("nightly_store_file") != null) {
signingConfig signingConfigs.nightly
} else {
signingConfig signingConfigs.debug
}
}
applicationVariants.all { variant ->
variant.resValue "string", "applicationId", variant.applicationId
2023-08-09 20:52:03 +02:00
buildGitChangelog()
2022-01-27 18:00:22 +01:00
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
}
lint {
abortOnError ABORT_ON_CHECK_FAILURE
lintConfig file("$rootDir/app/src/main/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")
// Ignore checks present in the snapshot
baseline file("lint-baseline.xml")
}
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'
implementation "androidx.camera:camera-core:1.2.3"
implementation "androidx.camera:camera-camera2:1.2.3"
implementation 'androidx.camera:camera-view:1.2.3'
implementation 'androidx.camera:camera-lifecycle:1.2.3'
2022-09-10 22:38:57 +02:00
testImplementation "junit:junit:4.13.2"
testImplementation "org.mockito:mockito-core:2.28.2"
testImplementation "org.robolectric:robolectric:4.12"
2024-04-16 00:45:55 +02:00
testImplementation "org.hamcrest:hamcrest-library:2.2"
2023-10-04 13:40:28 +02:00
testImplementation "com.google.code.gson:gson:2.8.9"
implementation fileTree(dir: "libs", include: ["*.jar"])
2023-10-04 13:40:28 +02:00
implementation "androidx.appcompat:appcompat:1.6.1"
implementation "androidx.preference:preference:1.2.1"
implementation "androidx.cardview:cardview:1.0.0"
implementation "androidx.recyclerview:recyclerview:1.3.2"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation "androidx.gridlayout:gridlayout:1.0.0"
implementation "androidx.palette:palette:1.0.0"
2023-10-04 13:40:28 +02:00
implementation "androidx.activity:activity:1.7.2"
implementation "androidx.fragment:fragment:1.6.2"
implementation "androidx.viewpager2:viewpager2:1.0.0"
2023-10-04 13:40:28 +02:00
implementation "com.google.android.material:material:1.9.0"
implementation 'com.google.android.flexbox:flexbox:3.0.0'
2023-10-04 13:40:28 +02:00
implementation "com.google.code.gson:gson:2.8.9"
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'
2024-04-15 23:04:43 +02:00
implementation 'com.google.protobuf:protobuf-javalite:3.25.3'
2022-03-31 11:36:26 +02:00
implementation 'com.android.volley:volley:1.2.1'
// Bouncy Castle is included directly in GB, to avoid pulling the entire dependency
2023-11-25 23:18:34 +01:00
// It's included in the org.bouncycastle.shaded package, to fix conflicts with
// roboelectric
//implementation 'org.bouncycastle:bcpkix-jdk18on:1.76'
//implementation 'org.bouncycastle:bcprov-jdk18on:1.76'
2023-10-02 10:48:10 +02:00
// 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
2024-04-07 15:39:03 +02:00
implementation 'com.jakewharton.threetenabp:threetenabp:1.4.7'
testImplementation 'org.threeten:threetenbp:1.6.9'
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:20240303'
2023-10-04 13:40:28 +02:00
// Fix Duplicate class build error
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
2021-04-23 10:11:04 +02:00
// Needed for Armenian transliteration
implementation group: 'org.ahocorasick', name: 'ahocorasick', version: '0.6.3'
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 {
java.srcDirs += "${protobuf.generatedFilesBaseDir}"
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 {
2024-04-15 23:04:43 +02:00
artifact = 'com.google.protobuf:protoc:3.25.3'
}
generateProtoTasks {
all().each { task ->
task.builtins {
2022-09-18 13:19:23 +02:00
java {
option 'lite'
}
}
}
}
}