Skip to content
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

Intergrate shared KMP module into the iOS app #313

Open
wants to merge 2 commits into
base: kmp
Choose a base branch
from

Conversation

0xtmphey
Copy link
Contributor

This PR wires android:shared KMP module to the iOS app and makes it possible to open KMP screens. Should be noted that the locker screen opens as a modal above the flutter app and its not the proper navigation solution :)

Changelog:

  • Update shared module's gradle config to make Room work on iOS
  • Implement AppDatabase.ios.kt
  • Run shared:embedAndSignAppleFrameworkForXcode gradle task during Xcode build to integrate kmp binary into the iOS app (build times are longer now)
  • Setup KMPApiBridge

Here is a preview:

preview.mov

@louwers
Copy link

louwers commented Mar 2, 2025

Fails with

/Users/bart/Library/Developer/Xcode/DerivedData/Runner-bulbrgiogyzifpfymlurhifkjoyp/Build/Intermediates.noindex/Runner.build/Debug-iphoneos/Runner.build/Script-5D12BEE52D57ED8100243610.sh: line 3: ./gradlew: No such file or directory

@louwers
Copy link

louwers commented Mar 2, 2025

After checking out gradle wrapper from master branch:

Showing All Messages
BUG! exception in phase 'semantic analysis' in source unit 'BuildScript' Unsupported class file major version 67

@0xtmphey
Copy link
Contributor Author

0xtmphey commented Mar 2, 2025

Hm, that's strange. I'll check it out

@WhosNickDoglio
Copy link
Contributor

Showing All Messages BUG! exception in phase 'semantic analysis' in source unit 'BuildScript' Unsupported class file major version 67

It sounds like you have JDK 23 installed which the current version of Gradle/Kotlin doesn't support. I believe if you lower the JDK version Gradle is using to 17 you should be fine. You can change this in Android Studio via Settings | Build, Execution, Deployment | Build Tools | Gradle | Gradle JDK

@louwers
Copy link

louwers commented Mar 2, 2025

I am not using Android Studio. I am using Xcode.

But yeah installing OpenJDK 17 and setting

 export JAVA_HOME=$(/usr/libexec/java_home -v 17)

Did the trick. That should be added to the README perhaps?

@louwers
Copy link

louwers commented Mar 2, 2025

Next error:

Error: Could not find or load main class org.jetbrains.kotlin.cli.utilities.MainKt

Showing All Messages
Starting a Gradle Daemon, 2 incompatible Daemons could not be reused, use --status for details

Task :buildSrc:processResources NO-SOURCE

Task :buildSrc:compileKotlin

Task :buildSrc:compileJava NO-SOURCE

Task :buildSrc:compileGroovy NO-SOURCE

Task :buildSrc:classes UP-TO-DATE

Task :buildSrc:jar

Configure project :

w: file:///Users/bart/src/mobile-app/android/build.gradle.kts:58:13: 'setter for buildDir: File!' is deprecated. Deprecated in Java

w: file:///Users/bart/src/mobile-app/android/build.gradle.kts:60:13: 'setter for buildDir: File!' is deprecated. Deprecated in Java

w: file:///Users/bart/src/mobile-app/android/build.gradle.kts:60:44: 'getter for buildDir: File!' is deprecated. Deprecated in Java

w: file:///Users/bart/src/mobile-app/android/build.gradle.kts:65:24: 'getter for buildDir: File!' is deprecated. Deprecated in Java

Configure project :app

WARNING: The option setting 'android.defaults.buildfeatures.buildconfig=true' is deprecated.

The current default is 'false'.

It will be removed in version 9.0 of the Android Gradle plugin.

To keep using this feature, add the following to your module-level build.gradle files:

android.buildFeatures.buildConfig = true

or from Android Studio, click: Refactor > Migrate BuildConfig to Gradle Build Files.

w: file:///Users/bart/src/mobile-app/android/app/build.gradle.kts:105:5: 'kotlinOptions(KotlinJvmOptionsDeprecated /* = KotlinJvmOptions */.() -> Unit): Unit' is deprecated. Please migrate to the compilerOptions DSL. More details are here: https://kotl.in/u1r8ln

You are applying Flutter's main Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/go/flutter-gradle-plugin-apply

w: file:///Users/bart/fvm/versions/3.22.3/packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts:107:40: Variable 'agpVersion' initializer is redundant

w: file:///Users/bart/fvm/versions/3.22.3/packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts:108:40: Variable 'kgpVersion' initializer is redundant

w: file:///Users/bart/fvm/versions/3.22.3/packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts:143:28: Parameter 'project' is never used

w: file:///Users/bart/fvm/versions/3.22.3/packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts:152:40: Variable 'agpVersion' initializer is redundant

w: file:///Users/bart/fvm/versions/3.22.3/packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts:167:55: 'Version' is deprecated. Deprecated in Java

w: file:///Users/bart/fvm/versions/3.22.3/packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts:195:56: Unnecessary non-null assertion (!!) on a non-null receiver of type Any

w: file:///Users/bart/fvm/versions/3.22.3/packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts:344:28: The corresponding parameter in the supertype 'Comparable' is named 'other'. This may cause problems when calling this function with named arguments.

Warning: unable to detect project KGP version. Skipping version checking.

This may be because you have applied KGP after the Flutter Gradle Plugin.

Configure project :shared

w: file:///Users/bart/src/mobile-app/android/shared/build.gradle.kts:22:13: 'kotlinOptions(KotlinJvmOptions.() -> Unit): Unit' is deprecated. Please migrate to the compilerOptions DSL. More details are here: https://kotl.in/u1r8ln

Task :shared:checkSandboxAndWriteProtection

Task :shared:checkKotlinGradlePluginConfigurationErrors SKIPPED

Task :shared:convertXmlValueResourcesForAppleMain NO-SOURCE

Task :shared:copyNonXmlValueResourcesForAppleMain NO-SOURCE

Task :shared:prepareComposeResourcesTaskForAppleMain NO-SOURCE

Task :shared:generateResourceAccessorsForAppleMain NO-SOURCE

Task :shared:convertXmlValueResourcesForCommonMain NO-SOURCE

Task :shared:copyNonXmlValueResourcesForCommonMain

Task :shared:prepareComposeResourcesTaskForCommonMain

Task :shared:generateResourceAccessorsForCommonMain

Task :shared:convertXmlValueResourcesForIosArm64Main NO-SOURCE

Task :shared:copyNonXmlValueResourcesForIosArm64Main NO-SOURCE

Task :shared:prepareComposeResourcesTaskForIosArm64Main NO-SOURCE

Task :shared:generateResourceAccessorsForIosArm64Main NO-SOURCE

Task :shared:convertXmlValueResourcesForIosMain NO-SOURCE

Task :shared:copyNonXmlValueResourcesForIosMain NO-SOURCE

Task :shared:prepareComposeResourcesTaskForIosMain NO-SOURCE

Task :shared:generateResourceAccessorsForIosMain NO-SOURCE

Task :shared:convertXmlValueResourcesForNativeMain NO-SOURCE

Task :shared:copyNonXmlValueResourcesForNativeMain NO-SOURCE

Task :shared:prepareComposeResourcesTaskForNativeMain NO-SOURCE

Task :shared:generateResourceAccessorsForNativeMain NO-SOURCE

Task :shared:generateActualResourceCollectorsForIosArm64Main

Task :shared:generateComposeResClass

Task :shared:generateExpectResourceCollectorsForCommonMain

Task :shared:kspKotlinIosArm64

Can't find env_blacklist file at /Users/bart/.konan/kotlin-native-prebuilt-macos-aarch64-2.1.0-RC/tools/env_blacklist.

Error: Could not find or load main class org.jetbrains.kotlin.cli.utilities.MainKt

Caused by: java.lang.ClassNotFoundException: org.jetbrains.kotlin.cli.utilities.MainKt

Task :shared:kspKotlinIosArm64 FAILED

Task :shared:copyRoomSchemas NO-SOURCE

FAILURE: Build failed with an exception.

  • What went wrong:

Execution failed for task ':shared:kspKotlinIosArm64'.

Process 'command '/opt/homebrew/Cellar/openjdk@17/17.0.14/libexec/openjdk.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

  • Try:

Run with --stacktrace option to get the stack trace.

Run with --info or --debug option to get more log output.

Run with --scan to get full insights.

Get more help at https://help.gradle.org.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.9/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 2m 20s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants