Skip to content

Commit 619dd8e

Browse files
bensonarafatfbernaly
authored andcommitted
refactor: Migrate google_mlkit_commons from Java to Kotlin (#842)
1 parent e0cab31 commit 619dd8e

15 files changed

Lines changed: 406 additions & 292 deletions

File tree

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ktlint: allow underscore in package names (Flutter plugin convention, e.g. com.google_mlkit_commons)
2+
[*.{kt,kts}]
3+
ktlint_standard_package-name = disabled

.github/workflows/code-analysis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,9 @@ jobs:
128128

129129
# Statically analyze the Dart code for any errors.
130130
- run: flutter analyze .
131+
132+
# Statically analyze Kotlin code (e.g. google_mlkit_commons Android) with ktlint.
133+
- name: Install ktlint
134+
run: brew install ktlint
135+
- name: Run ktlint on Kotlin code
136+
run: ktlint

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"java.configuration.updateBuildConfiguration": "automatic"
3+
}

packages/example/android/app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ android {
3333
}
3434

3535
aaptOptions {
36-
noCompress("tflite") // Your model's file extension: "tflite", "lite", etc.
36+
noCompress("tflite") // Your model's file extension: "tflite", "lite", etc.
3737
}
3838
}
3939

packages/example/android/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ allprojects {
55
}
66
}
77

8-
val newBuildDir: Directory = rootProject.layout.buildDirectory.dir("../../build").get()
8+
val newBuildDir: Directory =
9+
rootProject.layout.buildDirectory
10+
.dir("../../build")
11+
.get()
912
rootProject.layout.buildDirectory.value(newBuildDir)
1013

1114
subprojects {
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
pluginManagement {
2-
val flutterSdkPath = run {
3-
val properties = java.util.Properties()
4-
file("local.properties").inputStream().use { properties.load(it) }
5-
val flutterSdkPath = properties.getProperty("flutter.sdk")
6-
require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
7-
flutterSdkPath
8-
}
2+
val flutterSdkPath =
3+
run {
4+
val properties = java.util.Properties()
5+
file("local.properties").inputStream().use { properties.load(it) }
6+
val flutterSdkPath = properties.getProperty("flutter.sdk")
7+
require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
8+
flutterSdkPath
9+
}
910

1011
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
1112

@@ -19,7 +20,7 @@ pluginManagement {
1920
plugins {
2021
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
2122
id("com.android.application") version "8.13.0" apply false
22-
id("org.jetbrains.kotlin.android") version "2.2.0" apply false
23+
id("org.jetbrains.kotlin.android") version "2.2.20" apply false
2324
}
2425

2526
include(":app")

packages/google_mlkit_commons/android/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ group = "com.google_mlkit_commons"
22
version = "1.0"
33

44
buildscript {
5+
ext.kotlin_version = "2.2.20"
56
repositories {
67
google()
78
mavenCentral()
89
}
910

1011
dependencies {
1112
classpath("com.android.tools.build:gradle:8.13.0")
13+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.20")
1214
}
1315
}
1416

@@ -20,6 +22,7 @@ rootProject.allprojects {
2022
}
2123

2224
apply plugin: "com.android.library"
25+
apply plugin: "kotlin-android"
2326

2427
android {
2528
namespace = "com.google_mlkit_commons"
@@ -30,6 +33,14 @@ android {
3033
sourceCompatibility = JavaVersion.VERSION_11
3134
targetCompatibility = JavaVersion.VERSION_11
3235
}
36+
37+
kotlinOptions {
38+
jvmTarget = '11'
39+
}
40+
41+
sourceSets {
42+
main.java.srcDirs += "src/main/kotlin"
43+
}
3344

3445
defaultConfig {
3546
minSdk = 21
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0-milestone-1-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

packages/google_mlkit_commons/android/src/main/java/com/google_mlkit_commons/GenericModelManager.java

Lines changed: 0 additions & 118 deletions
This file was deleted.

packages/google_mlkit_commons/android/src/main/java/com/google_mlkit_commons/GoogleMlKitCommonsPlugin.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)