From 43d923841aa321eefac2416f50b38177f556d230 Mon Sep 17 00:00:00 2001 From: junsuPark Date: Tue, 3 Sep 2024 11:08:39 +0900 Subject: [PATCH] chore: migrate to Kotlin DSL --- android/app/build.gradle | 88 ---------------------------------- android/app/build.gradle.kts | 93 ++++++++++++++++++++++++++++++++++++ android/build.gradle | 43 ----------------- android/build.gradle.kts | 57 ++++++++++++++++++++++ android/settings.gradle | 25 ---------- android/settings.gradle.kts | 26 ++++++++++ 6 files changed, 176 insertions(+), 156 deletions(-) delete mode 100644 android/app/build.gradle create mode 100644 android/app/build.gradle.kts delete mode 100644 android/build.gradle create mode 100644 android/build.gradle.kts delete mode 100644 android/settings.gradle create mode 100644 android/settings.gradle.kts diff --git a/android/app/build.gradle b/android/app/build.gradle deleted file mode 100644 index 42cf5e62..00000000 --- a/android/app/build.gradle +++ /dev/null @@ -1,88 +0,0 @@ -plugins { - id "com.android.application" - id "kotlin-android" - id "dev.flutter.flutter-gradle-plugin" -} - -def localProperties = new Properties() -def localPropertiesFile = rootProject.file('local.properties') -if (localPropertiesFile.exists()) { - localPropertiesFile.withReader('UTF-8') { reader -> - localProperties.load(reader) - } -} - -def flutterVersionCode = localProperties.getProperty('flutter.versionCode') -if (flutterVersionCode == null) { - flutterVersionCode = '1' -} - -def flutterVersionName = localProperties.getProperty('flutter.versionName') -if (flutterVersionName == null) { - flutterVersionName = '1.0' -} - -def keystoreProperties = new Properties() -def keystorePropertiesFile = rootProject.file('key.properties') -if (keystorePropertiesFile.exists()) { - keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) -} - -android { - namespace 'org.sparcs.otlplus' - - compileSdk rootProject.ext.compileSdkVersion - - sourceSets { - main.java.srcDirs += 'src/main/kotlin' - } - - lint { - disable 'InvalidPackage' - } - - defaultConfig { - applicationId "org.sparcs.otlplus" - minSdkVersion 21 - targetSdkVersion rootProject.ext.targetSdkVersion - versionCode flutterVersionCode.toInteger() - versionName flutterVersionName - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - - signingConfigs { - release { - keyAlias keystoreProperties['keyAlias'] - keyPassword keystoreProperties['keyPassword'] - storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null - storePassword keystoreProperties['storePassword'] - } - } - buildTypes { - release { - signingConfig signingConfigs.release - } - } - packagingOptions { - jniLibs { - useLegacyPackaging = true - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 - } - kotlinOptions { - jvmTarget = '17' - } -} - -flutter { - source '../..' -} - -dependencies { - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test:runner:1.6.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' -} diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts new file mode 100644 index 00000000..cc67901f --- /dev/null +++ b/android/app/build.gradle.kts @@ -0,0 +1,93 @@ +import java.nio.charset.Charset +import java.util.Properties +import java.io.FileInputStream + +val localProperties = Properties().apply { + rootProject.file("local.properties").bufferedReader(Charset.forName("UTF-8")) + .use { reader -> load(reader) } +} + +val flutterVersionCode = localProperties.getProperty("flutter.versionCode") ?: "1" +val flutterVersionName = localProperties.getProperty("flutter.versionName") ?: "1.0" + +val keystoreProperties = Properties().apply { + val keystorePropertiesFile = rootProject.file("key.properties") + val keystorePropertiesFileExists = keystorePropertiesFile.exists() + if (keystorePropertiesFileExists) { + this.load(FileInputStream(keystorePropertiesFile)) + } +} + +plugins { + id("com.android.application") + id("kotlin-android") + id("dev.flutter.flutter-gradle-plugin") +} + +android { + namespace = "org.sparcs.otlplus" + compileSdk = rootProject.extra.get("compileSdkVersion")?.toString()?.toIntOrNull() + + sourceSets { + kotlin.sourceSets["main"].kotlin { + srcDir("src/main/kotlin") + } + } + + lint { + disable.addAll( + listOf( + "InvalidPackage", + ), + ) + } + + defaultConfig { + applicationId = "org.sparcs.otlplus" + minSdk = 21 + targetSdk = rootProject.extra.get("targetSdkVersion")?.toString()?.toIntOrNull() + versionCode = flutterVersionCode.toInt() + versionName = flutterVersionName + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + signingConfigs { + register("release") { + if (keystoreProperties.isNotEmpty()) { + keyAlias = keystoreProperties.getProperty("keyAlias")!! + keyPassword = keystoreProperties.getProperty("keyPassword")!! + storeFile = file(keystoreProperties.getProperty("storeFile")!!) + storePassword = keystoreProperties.getProperty("storePassword")!! + } + } + } + + buildTypes { + release { + signingConfig = signingConfigs.getByName("release") + } + } + + packaging { + jniLibs.keepDebugSymbols.add("**/*.so") + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + kotlinOptions { + jvmTarget = "17" + } +} + +flutter { + source = "../.." +} + +dependencies { + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test:runner:1.6.1") + androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1") +} diff --git a/android/build.gradle b/android/build.gradle deleted file mode 100644 index c2152574..00000000 --- a/android/build.gradle +++ /dev/null @@ -1,43 +0,0 @@ -import groovy.xml.XmlParser -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -allprojects { - repositories { - google() - mavenCentral() - } -} - -ext { - compileSdkVersion = 34 - targetSdkVersion = 34 - appCompatVersion = "1.7.0" -} - -rootProject.buildDir = '../build' -subprojects { - project.buildDir = "${rootProject.buildDir}/${project.name}" -} -subprojects { - afterEvaluate { - // check if `android` block is available and namespace isn't set - if(it.hasProperty('android') && it.android.namespace == null){ - def manifest = new XmlParser().parse(file(it.android.sourceSets.main.manifest.srcFile)) - android.namespace= manifest.@package - } - tasks.withType(KotlinCompile).tap { - configureEach { - if (project.plugins.hasPlugin("com.android.application") || project.plugins.hasPlugin("com.android.library")) { - kotlinOptions.jvmTarget = android.compileOptions.sourceCompatibility - } else { - kotlinOptions.jvmTarget = sourceCompatibility - } - } - } - } - project.evaluationDependsOn(':app') -} - -tasks.register("clean", Delete) { - delete rootProject.buildDir -} diff --git a/android/build.gradle.kts b/android/build.gradle.kts new file mode 100644 index 00000000..b9808124 --- /dev/null +++ b/android/build.gradle.kts @@ -0,0 +1,57 @@ +import com.android.build.gradle.BaseExtension +import com.android.build.gradle.LibraryExtension +import com.android.build.gradle.internal.dsl.BaseAppModuleExtension +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +allprojects { + repositories { + google() + mavenCentral() + } +} + +buildscript { + extra.apply { + set("compileSdkVersion", 34) + set("targetSdkVersion", 34) + } +} + +rootProject.layout.buildDirectory.set(file("../build")) +subprojects { + project.layout.buildDirectory.set(file("${rootProject.layout.buildDirectory.asFile.get().path}/${project.name}")) +} +subprojects { + // check if library extension block is available and namespace isn't set + afterEvaluate { + if (project.hasProperty("android")) { + val ext = try { + project.extensions.getByType() + } catch (_: Exception) { + project.extensions.getByType() + } + + ext.apply { + if (namespace == null) { + namespace = project.group.toString() + } + } + } + tasks.withType(KotlinCompile::class.java).configureEach { + if (project.plugins.hasPlugin("com.android.application") || project.plugins.hasPlugin("com.android.library")) { + kotlinOptions { + kotlinOptions.jvmTarget = + project.extensions.getByType().compileOptions.sourceCompatibility.toString() + } + } + } + } + + project.evaluationDependsOn(":app") +} + +tasks { + register("clean") { + delete(rootProject.layout.buildDirectory) + } +} diff --git a/android/settings.gradle b/android/settings.gradle deleted file mode 100644 index e7e2ba48..00000000 --- a/android/settings.gradle +++ /dev/null @@ -1,25 +0,0 @@ -pluginManagement { - def flutterSdkPath = { - def properties = new Properties() - file("local.properties").withInputStream { properties.load(it) } - def flutterSdkPath = properties.getProperty("flutter.sdk") - assert flutterSdkPath != null, "flutter.sdk not set in local.properties" - return flutterSdkPath - }() - - includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") - - repositories { - google() - mavenCentral() - gradlePluginPortal() - } -} - -plugins { - id "dev.flutter.flutter-plugin-loader" version "1.0.0" - id "com.android.application" version "8.3.0" apply false - id "org.jetbrains.kotlin.android" version "1.9.23" apply false -} - -include ":app" diff --git a/android/settings.gradle.kts b/android/settings.gradle.kts new file mode 100644 index 00000000..3547fac6 --- /dev/null +++ b/android/settings.gradle.kts @@ -0,0 +1,26 @@ +pluginManagement { + val flutterSdkPath = run { + val properties = java.util.Properties().apply { + file("local.properties") + .bufferedReader(java.nio.charset.Charset.forName("UTF-8")) + .use { reader -> load(reader) } + } + properties.getProperty("flutter.sdk") + ?: throw GradleException("flutter.sdk not set in local.properties") + } + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") + + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} + +plugins { + id("dev.flutter.flutter-plugin-loader") version "1.0.0" + id("com.android.application") version "8.3.0" apply false + id("org.jetbrains.kotlin.android") version "1.9.23" apply false +} + +include(":app")