Skip to content

Feature: Refactor Build Configuration: Kotlin DSL + Version Catalog #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
flutter-version: '3.29.3' # Set the desired Flutter version here
channel: 'stable'
- name: Install Dependencies
run: flutter pub get && cd example && flutter pub get && cd ..
run: flutter pub get && cd sample && flutter pub get && cd ..
- name: Lint Flutter
run: flutter analyze
Android:
Expand All @@ -41,7 +41,7 @@ jobs:
flutter-version: ${{ matrix.flutter-version }}
channel: 'stable'
- name: Install Dependencies
run: flutter pub get && cd example && flutter pub get && cd ..
run: flutter pub get && cd sample && flutter pub get && cd ..
- name: Lint Android
uses: musichin/ktlint-check@v3
with:
Expand All @@ -51,16 +51,16 @@ jobs:
!**/**.g.kt
!**/generated/**
- name: Test
run: flutter test && cd example && flutter test && cd ..
run: flutter test && cd sample && flutter test && cd ..
- name: Build Android Sample App
run: cd example && flutter build apk && cd ..
run: cd sample && flutter build apk && cd ..
iOS:
# TODO: Change back to macos-latest once it points to macOS 14 (Q2 '24)
runs-on: macos-14
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- run: touch example/ios/smile_config.json
- run: touch sample/ios/smile_config.json
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.29.3' # Set the desired Flutter version here
Expand All @@ -70,6 +70,6 @@ jobs:
with:
version: 1.14.3
- name: Install Dependencies
run: flutter pub get && cd example && flutter pub get && cd ..
run: flutter pub get && cd sample && flutter pub get && cd ..
- name: Build iOS Sample App
run: cd example/ios && pod install && flutter build ios --no-codesign && cd ..
run: cd sample/ios && pod install && flutter build ios --no-codesign && cd ..
4 changes: 2 additions & 2 deletions .github/workflows/release_ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ jobs:
run: |
sed -i "s/s.version\s*=\s*'[^']*'/s.version = '$(echo "${{ github.event.inputs.ios_release_version }}" | cut -c 2-)'/g" ios/smile_id.podspec
sed -i "s/s.dependency\s*'SmileID'\s*,\s*'[^']*'/s.dependency 'SmileID', '$(echo "${{ github.event.inputs.ios_release_version }}" | cut -c 2-)'/g" ios/smile_id.podspec
cd example/ios
cd sample/ios
pod update smile_id SmileID
- name: Commit and Push Changes
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"

git add ios/smile_id.podspec
git add example/ios/Podfile.lock
git add sample/ios/Podfile.lock
git commit -m "Update iOS SDK version to ${{ github.event.inputs.ios_release_version }}"
git push --set-upstream origin "ios-${{ github.event.inputs.ios_release_version }}"
- name: Create Pull Request
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ build/
.fvm/
smile_config.json

example/android/app/.cxx
sample/android/app/.cxx
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Release Notes

## 11.0.2

### Changed
* Renamed **example** folder to **sample** and replaced all usages of example in the project.
* Migrate all gradle files in the sample and SDK folders from Groovy to Kotlin.
* Add a `libs.versions.toml` file to share dependencies between the sample project and the Android SDK.
* Cleanup and minor code improvements on the gradlew files.
* Update Android Gradle Plugin and Kotlin version to the latest.
* Fail the `assemble` gradle task when `smile_config.json` file is not added in the assets folder.

## 11.0.1

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ Open the `sample` folder, then open the `ios` folder. Run the following commands
```ruby
# s.dependency "SmileID" # => Mind the version removal
```
* Specify the repo SmileID [iOS](https://github.com/smileidentity/ios) repo and pick a tag or branch podspec file in the Podfile example/ios/Podfile file:
* Specify the repo SmileID [iOS](https://github.com/smileidentity/ios) repo and pick a tag or branch podspec file in the Podfile sample/ios/Podfile file:
```ruby
pod 'SmileID', git: 'https://github.com/smileidentity/ios.git', branch: 'main'
```
* Run `pod install` in the `example/ios` folder
* Run `pod install` in the `sample/ios` folder
* If you have pod install issues run
```bash
pod deintegrate && pod install
Expand Down
131 changes: 0 additions & 131 deletions android/build.gradle

This file was deleted.

110 changes: 110 additions & 0 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
val kotlinVersion = findProperty("kotlinVersion") as String? ?: "2.1.21"
val kotlinCompilerExtension = findProperty("kotlinCompilerExtensionVersion") as String? ?: "1.5.14"

extra.apply {
set("kotlinVersion", kotlinVersion)
set("kotlinCompilerExtension", kotlinCompilerExtension)
}

buildscript {
val kotlinVersion = rootProject.findProperty("kotlinVersion") as String? ?: "2.1.21"

dependencies {
if (kotlinVersion.startsWith("2")) {
classpath("org.jetbrains.kotlin:compose-compiler-gradle-plugin:$kotlinVersion")
} else {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
}
}
}

allprojects {
repositories {
maven {
url = uri("https://central.sonatype.com/repository/maven-snapshots/")
}
}
}

plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
alias(libs.plugins.ktlint)
}

if (kotlinVersion.startsWith("2")) {
apply(plugin = "org.jetbrains.kotlin.plugin.compose")
}

android {
namespace = "com.smileidentity.flutter"
compileSdk = 35

defaultConfig {
minSdk = 21

// Read version from pubspec.yaml for setWrapperInfo
val pubspecYaml = File("../pubspec.yaml")
val pubspecText = pubspecYaml.readText()
val versionLine = Regex("""version:\s*(.+)""").find(pubspecText)
val version = if (versionLine != null) {
pubspecText.split(Regex("""version:\s*"""))[1].split("\n")[0].trim()
} else {
"11.0.0"
}
buildConfigField("String", "SMILE_ID_VERSION", "\"$version\"")
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = "17"
freeCompilerArgs += listOf(
"-Xskip-metadata-version-check",
) // metadata version check skip flag
}

sourceSets {
sourceSets["main"].java.srcDirs("src/main/kotlin")
sourceSets["test"].java.srcDirs("src/test/kotlin")
}

lint {
disable.add("NullSafeMutableLiveData")
}

buildFeatures {
buildConfig = true
compose = true
}
if (!kotlinVersion.startsWith("2")) {
composeOptions {
kotlinCompilerExtensionVersion = kotlinCompilerExtension
}
}
}

dependencies {
implementation(libs.smileid)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.viewmodel)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.fragment)
implementation(libs.kotlin.coroutines)
implementation(libs.kotlin.immutable.collections)
implementation(libs.mlkit)

testImplementation(libs.kotlin.test)
testImplementation(libs.mockk)
}

ktlint {
android.set(true)
filter {
exclude { it.file.path.contains(".g.kt") }
}
}
27 changes: 27 additions & 0 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[versions]
android-gradle-plugin = "8.10.1"
kotlin = "2.1.21"
kotlin-immutable-collections = "0.4.0"
ktlint-plugin = "12.3.0"
mockk = "1.14.2"
mlkit = "17.0.2"
smileid = "11.0.3"

[libraries]
androidx-core-ktx = { module = "androidx.core:core-ktx" }
androidx-compose-ui = { module = "androidx.compose.ui:ui" }
androidx-compose-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel-compose" }
androidx-compose-material3 = { module = "androidx.compose.material3:material3" }
androidx-fragment = { module = "androidx.fragment:fragment-ktx" }
kotlin-coroutines = { module ="org.jetbrains.kotlinx:kotlinx-coroutines-core" }
kotlin-immutable-collections = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version.ref = "kotlin-immutable-collections" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test" }
mlkit = { module = "com.google.mlkit:object-detection" , version.ref="mlkit" }
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
smileid = { module = "com.smileidentity:android-sdk", version.ref = "smileid" }

[plugins]
android-application = { id = "com.android.application", version.ref = "android-gradle-plugin" }
flutter-gradle-plugin = { id = "dev.flutter.flutter-gradle-plugin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint-plugin" }
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
1 change: 0 additions & 1 deletion android/settings.gradle

This file was deleted.

1 change: 1 addition & 0 deletions android/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "smile_id_flutter"
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import kotlin.test.Test
/*
* This demonstrates a simple unit test of the Kotlin portion of this plugin's implementation.
*
* Once you have built the plugin's example app, you can run these tests from the command
* line by running `./gradlew testDebugUnitTest` in the `example/android/` directory, or
* Once you have built the plugin's sample app, you can run these tests from the command
* line by running `./gradlew testDebugUnitTest` in the `sample/android/` directory, or
* you can run them directly from IDEs that support JUnit such as Android Studio.
*/
internal class SmileIDPluginTest {
Expand Down
Loading