From 9ed273a32e50600ce84fe1de64d993c7255478be Mon Sep 17 00:00:00 2001 From: Adam Szewera Date: Thu, 28 Dec 2023 22:37:27 +0100 Subject: [PATCH] Refactor groovy gradle files to kotlin dsl (#2022) ## Description: Refactor gradle build files to use Kotlin DSL instead of Groovy. There were also a bash script and a python script that needed to be updated because they relied on parsing the `build.gradle` files written in Groovy. This PR completes the work started in: https://github.com/syncthing/syncthing-android/pull/2000 --- app/build.gradle | 101 -------------------------------- app/build.gradle.kts | 110 +++++++++++++++++++++++++++++++++++ scripts/bump-version.bash | 12 ++-- syncthing/build-syncthing.py | 6 +- syncthing/build.gradle | 18 ------ syncthing/build.gradle.kts | 21 +++++++ 6 files changed, 140 insertions(+), 128 deletions(-) delete mode 100644 app/build.gradle create mode 100644 app/build.gradle.kts delete mode 100644 syncthing/build.gradle create mode 100644 syncthing/build.gradle.kts diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index da6c8dccc..000000000 --- a/app/build.gradle +++ /dev/null @@ -1,101 +0,0 @@ -plugins { - id 'com.android.application' - id 'com.github.ben-manes.versions' - id 'com.github.triplet.play' version '3.7.0' -} - -dependencies { - implementation 'eu.chainfire:libsuperuser:1.1.1' - implementation 'com.google.android.material:material:1.8.0' - implementation 'com.google.code.gson:gson:2.10.1' - implementation 'org.mindrot:jbcrypt:0.4' - implementation 'com.google.guava:guava:32.1.3-android' - implementation 'com.annimon:stream:1.2.2' - implementation 'com.android.volley:volley:1.2.1' - implementation 'commons-io:commons-io:2.11.0' - - implementation ('com.journeyapps:zxing-android-embedded:4.3.0') { transitive = false } - implementation 'com.google.zxing:core:3.4.1' - - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' - implementation 'com.google.dagger:dagger:2.49' - annotationProcessor 'com.google.dagger:dagger-compiler:2.49' - androidTestImplementation 'androidx.test:rules:1.4.0' - androidTestImplementation 'androidx.annotation:annotation:1.2.0' -} - -android { - // Changes to these values need to be reflected in `../docker/Dockerfile` - compileSdkVersion 33 - buildToolsVersion '33.0.2' - ndkVersion = "${ndkVersionShared}" - - buildTypes.debug.applicationIdSuffix ".debug" - buildFeatures.dataBinding = true - - defaultConfig { - applicationId "com.nutomic.syncthingandroid" - minSdkVersion 21 - targetSdkVersion 33 - versionCode 4379 - versionName "1.27.2-rc.2" - testApplicationId 'com.nutomic.syncthingandroid.test' - testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' - } - - signingConfigs { - release { - storeFile = { - def path = System.getenv("SYNCTHING_RELEASE_STORE_FILE") - return (path) ? file(path) : null - }() - storePassword System.getenv("SIGNING_PASSWORD") ?: "" - keyAlias System.getenv("SYNCTHING_RELEASE_KEY_ALIAS") ?: "" - keyPassword System.getenv("SIGNING_PASSWORD") ?: "" - } - } - buildTypes { - release { - signingConfig = signingConfigs.release.storeFile ? signingConfigs.release : null - } - debug { - debuggable true - jniDebuggable true - renderscriptDebuggable true - minifyEnabled false - } - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 - } - - // Otherwise libsyncthing.so doesn't appear where it should in installs - // based on app bundles, and thus nothing works. - packagingOptions { - jniLibs { - useLegacyPackaging = true - } - } -} - -play { - serviceAccountCredentials = file(System.getenv("SYNCTHING_RELEASE_PLAY_ACCOUNT_CONFIG_FILE") ?: 'keys.json') - track = 'beta' -} - -/** - * Some languages are not supported by Google Play, so we ignore them. - */ -task deleteUnsupportedPlayTranslations(type: Delete) { - delete 'src/main/play/listings/de_DE/' - delete 'src/main/play/listings/el-EL/' - delete 'src/main/play/listings/en/' - delete 'src/main/play/listings/eo/' - delete 'src/main/play/listings/eu/' - delete 'src/main/play/listings/nb/' - delete 'src/main/play/listings/nl_BE/' - delete 'src/main/play/listings/nn/' - delete 'src/main/play/listings/ta/' -} diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 000000000..af6c8a29c --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,110 @@ +plugins { + id("com.android.application") + id("com.github.ben-manes.versions") + id("com.github.triplet.play") version "3.7.0" +} + +dependencies { + implementation("eu.chainfire:libsuperuser:1.1.1") + implementation("com.google.android.material:material:1.8.0") + implementation("com.google.code.gson:gson:2.10.1") + implementation("org.mindrot:jbcrypt:0.4") + implementation("com.google.guava:guava:32.1.3-android") + implementation("com.annimon:stream:1.2.2") + implementation("com.android.volley:volley:1.2.1") + implementation("commons-io:commons-io:2.11.0") + + implementation("com.journeyapps:zxing-android-embedded:4.3.0") { + isTransitive = false + } + implementation("com.google.zxing:core:3.4.1") + + implementation("androidx.constraintlayout:constraintlayout:2.0.4") + implementation("com.google.dagger:dagger:2.49") + annotationProcessor("com.google.dagger:dagger-compiler:2.49") + androidTestImplementation("androidx.test:rules:1.4.0") + androidTestImplementation("androidx.annotation:annotation:1.2.0") +} + +android { + val ndkVersionShared = rootProject.extra.get("ndkVersionShared") + // Changes to these values need to be reflected in `../docker/Dockerfile` + compileSdk = 33 + buildToolsVersion = "33.0.2" + ndkVersion = "${ndkVersionShared}" + + buildFeatures { + dataBinding = true + } + + defaultConfig { + applicationId = "com.nutomic.syncthingandroid" + minSdk = 21 + targetSdk = 33 + versionCode = 4372 + versionName = "1.27.2-rc.2" + testApplicationId = "com.nutomic.syncthingandroid.test" + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + signingConfigs { + create("release") { + storeFile = System.getenv("SYNCTHING_RELEASE_STORE_FILE")?.let(::file) + storePassword = System.getenv("SIGNING_PASSWORD") + keyAlias = System.getenv("SYNCTHING_RELEASE_KEY_ALIAS") + keyPassword = System.getenv("SIGNING_PASSWORD") + } + } + + buildTypes { + getByName("debug") { + applicationIdSuffix = ".debug" + isDebuggable = true + isJniDebuggable = true + isRenderscriptDebuggable = true + isMinifyEnabled = false + } + getByName("release") { + signingConfig = signingConfigs.runCatching { getByName("release") } + .getOrNull() + .takeIf { it?.storeFile != null } + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + + // Otherwise libsyncthing.so doesn't appear where it should in installs + // based on app bundles, and thus nothing works. + packagingOptions { + jniLibs { + useLegacyPackaging = true + } + } +} + +play { + serviceAccountCredentials.set( + file(System.getenv("SYNCTHING_RELEASE_PLAY_ACCOUNT_CONFIG_FILE") ?: "keys.json") + ) + track.set("beta") +} + +/** + * Some languages are not supported by Google Play, so we ignore them. + */ +tasks.register("deleteUnsupportedPlayTranslations") { + delete( + "src/main/play/listings/de_DE/", + "src/main/play/listings/el-EL/", + "src/main/play/listings/en/", + "src/main/play/listings/eo/", + "src/main/play/listings/eu/", + "src/main/play/listings/nb/", + "src/main/play/listings/nl_BE/", + "src/main/play/listings/nn/", + "src/main/play/listings/ta/", + ) +} diff --git a/scripts/bump-version.bash b/scripts/bump-version.bash index 0345646b4..7ed1ac621 100755 --- a/scripts/bump-version.bash +++ b/scripts/bump-version.bash @@ -8,7 +8,7 @@ if ! git diff-index --exit-code --quiet HEAD; then fi NEW_VERSION_NAME=$1 -OLD_VERSION_NAME=$(grep "versionName" "app/build.gradle" | awk '{print $2}') +OLD_VERSION_NAME=$(grep "versionName" "app/build.gradle.kts" | awk '{print $3}') if [[ -z ${NEW_VERSION_NAME} ]] then echo "New version name is empty. Please set a new version. Current version: $OLD_VERSION_NAME" @@ -45,13 +45,13 @@ echo " Updating Version ----------------------------- " -OLD_VERSION_CODE=$(grep "versionCode" "app/build.gradle" -m 1 | awk '{print $2}') +OLD_VERSION_CODE=$(grep "versionCode" "app/build.gradle.kts" -m 1 | awk '{print $3}') NEW_VERSION_CODE=$(($OLD_VERSION_CODE + 1)) -sed -i -e "s/versionCode $OLD_VERSION_CODE/versionCode $NEW_VERSION_CODE/" "app/build.gradle" +sed -i -e "s/versionCode = $OLD_VERSION_CODE/versionCode = $NEW_VERSION_CODE/" "app/build.gradle.kts" -OLD_VERSION_NAME=$(grep "versionName" "app/build.gradle" | awk '{print $2}') -sed -i -e "s/$OLD_VERSION_NAME/\"$1\"/" "app/build.gradle" -git add "app/build.gradle" $CHANGELOG +OLD_VERSION_NAME=$(grep "versionName" "app/build.gradle.kts" | awk '{print $3}') +sed -i -e "s/$OLD_VERSION_NAME/\"$1\"/" "app/build.gradle.kts" +git add "app/build.gradle.kts" $CHANGELOG git commit -m "Bumped version to $NEW_VERSION_NAME" git tag -a ${NEW_VERSION_NAME} -m " $NEW_VERSION_NAME diff --git a/syncthing/build-syncthing.py b/syncthing/build-syncthing.py index 7cb2c2c75..dd45d0bcf 100644 --- a/syncthing/build-syncthing.py +++ b/syncthing/build-syncthing.py @@ -47,11 +47,11 @@ def fail(message, *args, **kwargs): def get_min_sdk(project_dir): - with open(os.path.join(project_dir, 'app', 'build.gradle')) as file_handle: + with open(os.path.join(project_dir, 'app', 'build.gradle.kts')) as file_handle: for line in file_handle: tokens = list(filter(None, line.split())) - if len(tokens) == 2 and tokens[0] == 'minSdkVersion': - return int(tokens[1]) + if len(tokens) == 3 and tokens[0] == 'minSdk': + return int(tokens[2]) fail('Failed to find minSdkVersion') diff --git a/syncthing/build.gradle b/syncthing/build.gradle deleted file mode 100644 index 6740aee59..000000000 --- a/syncthing/build.gradle +++ /dev/null @@ -1,18 +0,0 @@ -plugins { - id 'ru.vyarus.use-python' version '3.0.0' -} - -task buildNative(type: PythonTask) { - environment "NDK_VERSION", "$ndkVersionShared" - inputs.dir("$projectDir/src/") - outputs.dir("$projectDir/../app/src/main/jniLibs/") - command = "-u ./build-syncthing.py" -} - -/** - * Use separate task instead of standard clean(), so these folders aren't deleted by `gradle clean`. - */ -task cleanNative(type: Delete) { - delete "$projectDir/../app/src/main/jniLibs/" - delete "gobuild" -} diff --git a/syncthing/build.gradle.kts b/syncthing/build.gradle.kts new file mode 100644 index 000000000..8a0558732 --- /dev/null +++ b/syncthing/build.gradle.kts @@ -0,0 +1,21 @@ +import ru.vyarus.gradle.plugin.python.task.PythonTask + +plugins { + id("ru.vyarus.use-python") version "3.0.0" +} + +tasks.register("buildNative") { + val ndkVersionShared = rootProject.extra.get("ndkVersionShared") + environment("NDK_VERSION", "$ndkVersionShared") + inputs.dir("$projectDir/src/") + outputs.dir("$projectDir/../app/src/main/jniLibs/") + command = "-u ./build-syncthing.py" +} + +/** + * Use separate task instead of standard clean(), so these folders aren't deleted by `gradle clean`. + */ +tasks.register("cleanNative") { + delete("$projectDir/../app/src/main/jniLibs/") + delete("gobuild") +}