Skip to content

Commit 2eafd22

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

15 files changed

Lines changed: 401 additions & 296 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

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.3.10" apply false
2324
}
2425

2526
include(":app")

packages/example/pubspec.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,10 @@ packages:
470470
dependency: transitive
471471
description:
472472
name: meta
473-
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
473+
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
474474
url: "https://pub.dev"
475475
source: hosted
476-
version: "1.16.0"
476+
version: "1.17.0"
477477
mime:
478478
dependency: transitive
479479
description:
@@ -611,10 +611,10 @@ packages:
611611
dependency: transitive
612612
description:
613613
name: test_api
614-
sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
614+
sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55
615615
url: "https://pub.dev"
616616
source: hosted
617-
version: "0.7.6"
617+
version: "0.7.7"
618618
typed_data:
619619
dependency: transitive
620620
description:

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.3.10"
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.3.10")
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)