From e039919274e7d11abf0482f4006c50033b2fc978 Mon Sep 17 00:00:00 2001 From: FunkyMuse Date: Mon, 31 Jul 2023 12:31:48 +0200 Subject: [PATCH] fix: build pipeline and migrate to gradle kts and version catalogs --- app/build.gradle | 83 ---------------- app/build.gradle.kts | 97 +++++++++++++++++++ app/src/main/AndroidManifest.xml | 1 - .../camera/activities/MainActivity.kt | 12 +-- .../camera/activities/SettingsActivity.kt | 10 +- .../camera/helpers/PhotoProcessor.kt | 6 +- .../simplemobiletools/camera/models/MySize.kt | 2 +- .../camera/models/VideoQuality.kt | 2 +- .../camera/views/ShadowDrawable.kt | 2 +- build.gradle | 30 ------ build.gradle.kts | 4 + gradle.properties | 11 ++- gradle/libs.versions.toml | 51 ++++++++++ gradle/wrapper/gradle-wrapper.properties | 4 +- settings.gradle | 1 - settings.gradle.kts | 16 +++ 16 files changed, 198 insertions(+), 134 deletions(-) delete mode 100644 app/build.gradle create mode 100644 app/build.gradle.kts delete mode 100644 build.gradle create mode 100644 build.gradle.kts create mode 100644 gradle/libs.versions.toml delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index 9df1457d..00000000 --- a/app/build.gradle +++ /dev/null @@ -1,83 +0,0 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' - -def keystorePropertiesFile = rootProject.file("keystore.properties") -def keystoreProperties = new Properties() -if (keystorePropertiesFile.exists()) { - keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) -} - -android { - compileSdkVersion 33 - - defaultConfig { - applicationId "com.simplemobiletools.camera" - minSdkVersion 29 - targetSdkVersion 33 - versionCode 87 - versionName "5.7.0" - setProperty("archivesBaseName", "camera") - vectorDrawables.useSupportLibrary = true - } - - signingConfigs { - if (keystorePropertiesFile.exists()) { - release { - keyAlias keystoreProperties['keyAlias'] - keyPassword keystoreProperties['keyPassword'] - storeFile file(keystoreProperties['storeFile']) - storePassword keystoreProperties['storePassword'] - } - } - } - - buildFeatures { - buildConfig true - viewBinding true - } - - buildTypes { - debug { - applicationIdSuffix ".debug" - } - release { - minifyEnabled true - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - if (keystorePropertiesFile.exists()) { - signingConfig signingConfigs.release - } - } - } - - flavorDimensions "variants" - productFlavors { - core {} - fdroid {} - prepaid {} - } - - sourceSets { - main.java.srcDirs += 'src/main/kotlin' - } - - lintOptions { - checkReleaseBuilds false - abortOnError false - } -} - -dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:fad9b2cdb0' - implementation 'androidx.documentfile:documentfile:1.0.1' - implementation "androidx.exifinterface:exifinterface:1.3.5" - implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.5.1" - implementation 'androidx.window:window:1.1.0-alpha03' - - def camerax_version = '1.2.0-rc01' - implementation "androidx.camera:camera-core:$camerax_version" - implementation "androidx.camera:camera-camera2:$camerax_version" - implementation "androidx.camera:camera-video:$camerax_version" - implementation "androidx.camera:camera-extensions:$camerax_version" - implementation "androidx.camera:camera-lifecycle:$camerax_version" - implementation "androidx.camera:camera-view:$camerax_version" -} diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 00000000..e1960af5 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,97 @@ +import java.io.FileInputStream +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.jetbrains.kotlin.konan.properties.Properties + +plugins { + alias(libs.plugins.android) + alias(libs.plugins.kotlinAndroid) +} + +val keystorePropertiesFile: File = rootProject.file("keystore.properties") +val keystoreProperties = Properties() +if (keystorePropertiesFile.exists()) { + keystoreProperties.load(FileInputStream(keystorePropertiesFile)) +} + +android { + compileSdk = project.libs.versions.app.build.compileSDKVersion.get().toInt() + + defaultConfig { + applicationId = libs.versions.app.version.appId.get() + minSdk = project.libs.versions.app.build.minimumSDK.get().toInt() + targetSdk = project.libs.versions.app.build.targetSDK.get().toInt() + versionName = project.libs.versions.app.version.versionName.get() + versionCode = project.libs.versions.app.version.versionCode.get().toInt() + setProperty("archivesBaseName", "camera") + vectorDrawables.useSupportLibrary = true + } + + signingConfigs { + if (keystorePropertiesFile.exists()) { + register("release") { + keyAlias = keystoreProperties.getProperty("keyAlias") + keyPassword = keystoreProperties.getProperty("keyPassword") + storeFile = file(keystoreProperties.getProperty("storeFile")) + storePassword = keystoreProperties.getProperty("storePassword") + } + } + } + + buildFeatures { + viewBinding = true + buildConfig = true + } + + buildTypes { + debug { + applicationIdSuffix = ".debug" + } + release { + isMinifyEnabled = true + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + if (keystorePropertiesFile.exists()) { + signingConfig = signingConfigs.getByName("release") + } + } + } + + flavorDimensions.add("variants") + productFlavors { + register("core") + register("fdroid") + register("prepaid") + } + + sourceSets { + getByName("main").java.srcDirs("src/main/kotlin") + } + + compileOptions { + val currentJavaVersionFromLibs = JavaVersion.valueOf(libs.versions.app.build.javaVersion.get().toString()) + sourceCompatibility = currentJavaVersionFromLibs + targetCompatibility = currentJavaVersionFromLibs + } + + tasks.withType { + kotlinOptions.jvmTarget = project.libs.versions.app.build.kotlinJVMTarget.get() + } + + namespace = "com.simplemobiletools.camera" + + lint { + checkReleaseBuilds = false + abortOnError = false + } +} + +dependencies { + implementation(libs.simple.tools.commons) + implementation(libs.bundles.androidx.camera) + implementation(libs.androidx.documentfile) + implementation(libs.androidx.exifinterface) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation(libs.androidx.window) +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 053bf145..2f9242cf 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ throw IllegalStateException("Unsupported tab position ${tab.position}") } } else { - toast(R.string.no_audio_permissions) + toast(com.simplemobiletools.commons.R.string.no_audio_permissions) selectPhotoTab() if (isVideoCaptureIntent()) { finish() @@ -235,7 +235,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera if (grantedRecordAudioPermission) { initializeCamera(false) } else { - toast(R.string.no_audio_permissions) + toast(com.simplemobiletools.commons.R.string.no_audio_permissions) if (isThirdPartyIntent()) { finish() } else { @@ -247,12 +247,12 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera } } } else { - toast(R.string.no_storage_permissions) + toast(com.simplemobiletools.commons.R.string.no_storage_permissions) finish() } } } else { - toast(R.string.no_camera_permissions) + toast(com.simplemobiletools.commons.R.string.no_camera_permissions) finish() } } @@ -314,7 +314,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera topMargin = safeInsetTop } - val marginBottom = safeInsetBottom + navigationBarHeight + resources.getDimensionPixelSize(R.dimen.bigger_margin) + val marginBottom = safeInsetBottom + navigationBarHeight + resources.getDimensionPixelSize(com.simplemobiletools.commons.R.dimen.bigger_margin) binding.shutter.updateLayoutParams { bottomMargin = marginBottom @@ -861,7 +861,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera private fun setButtonColors(button: MaterialButton) { val primaryColor = getProperPrimaryColor() val states = arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)) - val iconColors = intArrayOf(ContextCompat.getColor(this, R.color.md_grey_white), primaryColor) + val iconColors = intArrayOf(ContextCompat.getColor(this, com.simplemobiletools.commons.R.color.md_grey_white), primaryColor) button.iconTint = ColorStateList(states, iconColors) } diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt index 0aff44f3..fd684d7e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt @@ -66,7 +66,7 @@ class SettingsActivity : SimpleActivity() { private fun refreshMenuItems() { binding.settingsToolbar.menu.apply { - findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations) + findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(com.simplemobiletools.commons.R.bool.hide_google_relations) } } @@ -125,9 +125,9 @@ class SettingsActivity : SimpleActivity() { FAQItem(R.string.faq_1_title, R.string.faq_1_text) ) - if (!resources.getBoolean(R.bool.hide_google_relations)) { - faqItems.add(FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons)) - faqItems.add(FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons)) + if (!resources.getBoolean(com.simplemobiletools.commons.R.bool.hide_google_relations)) { + faqItems.add(FAQItem(com.simplemobiletools.commons.R.string.faq_2_title_commons, com.simplemobiletools.commons.R.string.faq_2_text_commons)) + faqItems.add(FAQItem(com.simplemobiletools.commons.R.string.faq_6_title_commons, com.simplemobiletools.commons.R.string.faq_6_text_commons)) } startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true) @@ -183,7 +183,7 @@ class SettingsActivity : SimpleActivity() { if (checkLocationPermission()) { updateSavePhotoVideoLocationConfig(true) } else { - OpenDeviceSettingsDialog(activity = this@SettingsActivity, message = getString(R.string.allow_location_permission)) + OpenDeviceSettingsDialog(activity = this@SettingsActivity, message = getString(com.simplemobiletools.commons.R.string.allow_location_permission)) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/PhotoProcessor.kt b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/PhotoProcessor.kt index f899bb85..d3cf91ff 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/PhotoProcessor.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/PhotoProcessor.kt @@ -98,13 +98,15 @@ class PhotoProcessor( try { image = Bitmap.createBitmap(image, 0, 0, image.width, image.height, matrix, false) } catch (e: OutOfMemoryError) { - activity.toast(R.string.out_of_memory_error) + activity.toast(com.simplemobiletools.commons.R.string.out_of_memory_error) } } } try { - image.compress(Bitmap.CompressFormat.JPEG, activity.config.photoQuality, fos) + if (fos != null) { + image.compress(Bitmap.CompressFormat.JPEG, activity.config.photoQuality, fos) + } if (!isThirdPartyIntent) { activity.saveImageRotation(path, totalRotation) } diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/models/MySize.kt b/app/src/main/kotlin/com/simplemobiletools/camera/models/MySize.kt index 265bcab7..2d14b1b5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/models/MySize.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/models/MySize.kt @@ -63,7 +63,7 @@ data class MySize(val width: Int, val height: Int, val isFullScreen: Boolean = f isNineteenToEight() -> "19:8" isSquare() -> "1:1" isTwoToOne() -> "2:1" - else -> context.resources.getString(R.string.other) + else -> context.resources.getString(com.simplemobiletools.commons.R.string.other) } @DrawableRes diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/models/VideoQuality.kt b/app/src/main/kotlin/com/simplemobiletools/camera/models/VideoQuality.kt index 287b52bd..c548d2ed 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/models/VideoQuality.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/models/VideoQuality.kt @@ -51,7 +51,7 @@ enum class VideoQuality(val width: Int, val height: Int) { isNineteenToEight() -> "19:8" isSquare() -> "1:1" isTwoToOne() -> "2:1" - else -> context.resources.getString(R.string.other) + else -> context.resources.getString(com.simplemobiletools.commons.R.string.other) } @DrawableRes diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/views/ShadowDrawable.kt b/app/src/main/kotlin/com/simplemobiletools/camera/views/ShadowDrawable.kt index 99c5dfd6..eaaaa812 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/views/ShadowDrawable.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/views/ShadowDrawable.kt @@ -65,7 +65,7 @@ class ShadowDrawable(context: Context, private val drawable: Drawable, @StyleRes if (styleResId != 0) { val obtainStyledAttributes = context.obtainStyledAttributes(styleResId, R.styleable.ShadowDrawable) shadowColor = - obtainStyledAttributes.getColor(R.styleable.ShadowDrawable_android_shadowColor, ContextCompat.getColor(context, R.color.md_grey_400_dark)) + obtainStyledAttributes.getColor(R.styleable.ShadowDrawable_android_shadowColor, ContextCompat.getColor(context, com.simplemobiletools.commons.R.color.md_grey_400_dark)) shadowDx = obtainStyledAttributes.getFloat(R.styleable.ShadowDrawable_android_shadowDx, 0f).toInt() shadowDy = obtainStyledAttributes.getFloat(R.styleable.ShadowDrawable_android_shadowDy, 0f).toInt() val shadowRadius = obtainStyledAttributes.getFloat(R.styleable.ShadowDrawable_android_shadowRadius, 0.0f).coerceAtLeast(0.0f) diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 94400f3a..00000000 --- a/build.gradle +++ /dev/null @@ -1,30 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - -buildscript { - ext.kotlin_version = '1.7.10' - - repositories { - google() - mavenCentral() - } - - dependencies { - classpath 'com.android.tools.build:gradle:7.3.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - google() - mavenCentral() - maven { url 'https://jitpack.io' } - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..f0236317 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,4 @@ +plugins { + alias(libs.plugins.android).apply(false) + alias(libs.plugins.kotlinAndroid).apply(false) +} diff --git a/gradle.properties b/gradle.properties index dbb7bf70..3b461d95 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,11 @@ -android.enableJetifier=true +org.gradle.jvmargs=-Xmx4g -XX:+UseGCOverheadLimit -XX:GCTimeLimit=10 -Dfile.encoding=UTF-8 -XX:+UseParallelGC +kotlin.code.style=official android.useAndroidX=true +android.enableJetifier=true +org.gradle.parallel=true +org.gradle.caching=true +org.gradle.vfs.watch=true +org.gradle.configureondemand=true +org.gradle.unsafe.configuration-cache=true +org.gradle.unsafe.configuration-cache-problems=warn +android.nonTransitiveRClass=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 00000000..8875fc36 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,51 @@ +[versions] +#jetbrains +kotlin = "1.9.0" +#Androidx +androidx-document-file = "1.0.1" +androidx-exif-interface = "1.3.6" +androidx-lifecycle = "2.6.1" +androidx-window = "1.2.0-beta01" +androidx-camera = "1.3.0-beta02" +androidx-ktx = "2.6.1" +#Simple tools +lifecycleRuntimeKtx = "2.6.1" +simple-commons = "53ad279f5e" +#Gradle +gradlePlugins-agp = "8.1.0" +#build +app-build-compileSDKVersion = "34" +app-build-targetSDK = "33" +app-build-minimumSDK = "23" +app-build-javaVersion = "VERSION_17" +app-build-kotlinJVMTarget = "17" +#versioning +app-version-appId = "com.simplemobiletools.camera" +app-version-versionCode = "87" +app-version-versionName = "5.7.0" +[libraries] +#Android X +androidx-camera-core = { module = "androidx.camera:camera-core", version.ref = "androidx-camera" } +androidx-camera-camera2 = { module = "androidx.camera:camera-camera2", version.ref = "androidx-camera" } +androidx-camera-video = { module = "androidx.camera:camera-video", version.ref = "androidx-camera" } +androidx-camera-extensions = { module = "androidx.camera:camera-extensions", version.ref = "androidx-camera" } +androidx-camera-lifecycle = { module = "androidx.camera:camera-lifecycle", version.ref = "androidx-camera" } +androidx-camera-view = { module = "androidx.camera:camera-view", version.ref = "androidx-camera" } +androidx-window = { module = "androidx.window:window", version.ref = "androidx-window" } +androidx-lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidx-ktx" } +androidx-exifinterface = { module = "androidx.exifinterface:exifinterface", version.ref = "androidx-exif-interface" } +androidx-documentfile = { module = "androidx.documentfile:documentfile", version.ref = "androidx-document-file" } +#Simple Mobile Tools +simple-tools-commons = { module = "com.github.SimpleMobileTools:Simple-Commons", version.ref = "simple-commons" } +[bundles] +androidx-camera = [ + "androidx-camera-core", + "androidx-camera-camera2", + "androidx-camera-video", + "androidx-camera-extensions", + "androidx-camera-lifecycle", + "androidx-camera-view" +] +[plugins] +android = { id = "com.android.application", version.ref = "gradlePlugins-agp" } +kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index aa8192b8..5e4d7c19 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Nov 05 21:17:11 CET 2020 +#Mon Jul 31 10:49:23 CEST 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index e7b4def4..00000000 --- a/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -include ':app' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..45478cbe --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,16 @@ +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + maven { setUrl("https://jitpack.io") } + } +} +include(":app")