Code Monkey home page Code Monkey logo

kmm-basic-sample's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kmm-basic-sample's Issues

Github Action runs forever

Since you updated to 1.4.0 the github action runs forever... 😰
Nur sure if it's because of the update or github related 🤷‍♂️

After involving XCTest, get build error "Building for iOS Simulator, but linking in dylib built for iOS...

Hey, I try to use KMM for 1 of our project, for now experiment only. However I got this architecture compatible issue, and raised an issue in Stackoverflow. Would you mind to take look of this? KMM is supporting native iOS framework, I really want to see your potential ability. Now shared library is connect in Xcode, it works means I could run iOS app, perform unit test, but when I add XCTest support, it failed as below.

https://stackoverflow.com/questions/74094854/kmm-after-involving-xctest-get-build-error-building-for-ios-simulator-but-li
Screen Shot 2022-10-17 at 16 19 35

Can't build for iOS with kotlin 1.3.20

I downloaded the project, added local.properties in order to set the sdk path, opened the xcodeproj file and tried to build as is (cmd+b). I am getting the following issue:

Execution failed for task ':greeting:copyFramework'.
> Cannot find a link task for the binary kind 'FRAMEWORK' and the build type 'DEBUG'

(PS: Android project is running without any issue)

Dependency of commonMain not visible in commonMain source set, but in androidMain

Versions:

  • Kotlin Multiplatform Mobile Plugin version: 0.1.1-release-51-Studio4.1
  • Kotlin plugin version: 1.4.10-release-Studio4.1-1
  • Android Studio version: 4.1. RC 2
  • OS: macOS Mojave 10.14.6
  • Gradle: 6.5
  • Kotlin gradle plugin: 1.4.0
  • Build gradle: 4.0.1

How to reproduce:
When adding dependencies to commonMain in newly generated project. Dependencies are visible for the androidMain source set but not for commonMain. See attached screenshot
Zrzut ekranu 2020-09-11 o 14 21 24

iOS static library

Now kotlinMpp builds some_name.framework (dynamic framework). Can KotlinMpp build some_name.a (static library)?

Code signing "*****.framework" failed when uploading

Integrated the framework for our project with "Do Not Embed", with that it worked only on the simulator and not in the device.
Then changed the to "Embed & Sign" then it worked on Simulator & Device.

But when uploaded it caused an error
Code signing "**.framework" failed.

Can you help me fix the upload issue?

Error: Building for iOS Simulator-arm64 but attempting to link with file built for iOS Simulator-x86_64 (M1)

Hi, I am trying to integrate KMM project as a pod to my sample Xcode Project. I can link the KMM Pod to my Xcode project. However if I try to call one of the function, below error yielded. If I do not call any of the KMM function, it can run the app in my simulator.

ViewController

import UIKit
import Multiplatform

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        let a = Greeting()
        a.greeting()
    }
}
ld: warning: ignoring file /Users/avjiang/Developments/Multiplatform/SharedCode/build/cocoapods/framework/Multiplatform.framework/Multiplatform, building for iOS Simulator-arm64 but attempting to link with file built for iOS Simulator-x86_64
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_MultiplatformGreeting", referenced from:
      objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The KMM application is just a simple app. There is a Greeting class inside SharedCode -> commonMain -> kotlin -> Greeting

Below is my configuration for build.gradle.kts

import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    id("com.android.library")
}

version = "1.0"

kotlin {
    android()

    cocoapods {
        // Configure fields required by CocoaPods.
        summary = "Some description for a Kotlin/Native module"
        homepage = "Link to a Kotlin/Native module homepage"
        frameworkName = "Multiplatform"
        ios.deploymentTarget = "13.5"
        podfile = project.file("/Users/avjiang/Developments/TestKotlinMultiplatformPod/Podfile")
    }

    val iosTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
        if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
            ::iosArm64
        else
            ::iosX64

    iosTarget("ios") { }

    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val androidMain by getting
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.13.2")
            }
        }
        val iosMain by getting
        val iosTest by getting
    }
}

android {
    compileSdkVersion(30)
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdkVersion(19)
        targetSdkVersion(30)
    }
}

And this is my project build.gradle.kts

buildscript {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20")
        classpath("com.android.tools.build:gradle:4.2.2")
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

tasks.register("clean", Delete::class) {
    delete(rootProject.buildDir)
}

Basically I am just following the tutorial from https://kotlinlang.org/docs/mobile/create-first-app.html. Nothing complex yet. Is there anything I missed out?

My machine configuration:
Mac mini M1
Xcode 13 beta 2
MacOS 11.4

Thank you

iOS armv7 build

Kotlin/Native supports building for iOS armv7 targets now, but the gradle script for the library only builds arm64 or x86_64 depending on the target.
How can I build a universal armv7+arm64 app for release?

FR: Add watchOS support

It'll be really cool If I could add a watchOS target to the already existing ios app. If I add a target through Xcode, it is unable to access the "shared" files and I get this error "Building for watchOS Simulator, but the linked framework 'shared.framework' was built for iOS Simulator. kotlin project"
I couldn't find a lot of resources on this so I think this could be a nice addition to this project.

./gradlew :greeting:iosTest doesn't open iOS simulator.

I'm running ./gradlew :greeting:iosTest in terminal and getting following output:

> Configure project :androidApp
Kotlin Multiplatform Projects are an experimental feature.

> Task :greeting:iosTest
[==========] Running 2 tests from 1 test cases.
[----------] Global test environment set-up.
[----------] 2 tests from org.greeting.CalculatorTest
[ RUN      ] org.greeting.CalculatorTest.testSum
[       OK ] org.greeting.CalculatorTest.testSum (0 ms)
[ RUN      ] org.greeting.CalculatorTest.testFactory
[       OK ] org.greeting.CalculatorTest.testFactory (1 ms)
[----------] 2 tests from org.greeting.CalculatorTest (1 ms total)

[----------] Global test environment tear-down
[==========] 2 tests from 1 test cases ran. (1 ms total)
[  PASSED  ] 2 tests.

BUILD SUCCESSFUL in 2s
3 actionable tasks: 1 executed, 2 up-to-date

Base on your documentation I expected iOS simulator to open and run iOS tests from iosApp/iosAppTests/iosAppTests.swift, however only common tests did run.

AndroidKeystoreAesGcm.encryptInternal error

Our crash monitoring is reporting a lot of occurrences of a crash for one single user running Android 13 on Xiaomi Poco F3, with the app in the background ,RAM free: 3.02 GB and Disk free: 67.14 GB.

I couldn't reproduce the issue in any way.

Fatal Exception: java.security.KeyStoreException: the master key android-keystore://_androidx_security_master_key_ exists but is unusable
       at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewMasterKey(AndroidKeysetManager.java:275)
       at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:236)
       at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:123)
       at com.amplifyframework.core.store.EncryptedKeyValueRepository$sharedPreferences$2.invoke(EncryptedKeyValueRepository.kt:35)
       at com.amplifyframework.core.store.EncryptedKeyValueRepository$sharedPreferences$2.invoke(EncryptedKeyValueRepository.kt:34)
       at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
       at com.amplifyframework.core.store.EncryptedKeyValueRepository.getSharedPreferences$com_amplifyframework_core(EncryptedKeyValueRepository.kt:34)
       at com.amplifyframework.core.store.EncryptedKeyValueRepository.get(EncryptedKeyValueRepository.kt:56)
       at com.amplifyframework.auth.cognito.data.AWSCognitoAuthCredentialStore.retrieveCredential(AWSCognitoAuthCredentialStore.kt:63)
       at com.amplifyframework.auth.cognito.actions.CredentialStoreCognitoActions$loadCredentialStoreAction$$inlined$invoke$1.execute(Action.kt:70)
       at com.amplifyframework.statemachine.ConcurrentEffectExecutor$execute$1$1.invokeSuspend(ConcurrentEffectExecutor.kt:26)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt)
Caused by java.security.InvalidKeyException: Keystore operation failed
       at android.security.keystore2.KeyStoreCryptoOperationUtils.getInvalidKeyException(:11)
       at android.security.keystore2.KeyStoreCryptoOperationUtils.getExceptionForCipherInit(:16)
       at android.security.keystore2.AndroidKeyStoreCipherSpiBase.ensureKeystoreOperationInitialized(:70)
       at android.security.keystore2.AndroidKeyStoreCipherSpiBase.engineInit(:255)
       at javax.crypto.Cipher.tryTransformWithProvider(Cipher.java:2985)
       at javax.crypto.Cipher.tryCombinations(Cipher.java:2892)
       at javax.crypto.Cipher$SpiAndProviderUpdater.updateAndGetSpiAndProvider(Cipher.java:2797)
       at javax.crypto.Cipher.chooseProvider(Cipher.java:774)
       at javax.crypto.Cipher.init(Cipher.java:1144)
       at javax.crypto.Cipher.init(Cipher.java:1085)
       at com.google.crypto.tink.integration.android.AndroidKeystoreAesGcm.encryptInternal(AndroidKeystoreAesGcm.java:84)
       at com.google.crypto.tink.integration.android.AndroidKeystoreAesGcm.encrypt(AndroidKeystoreAesGcm.java:72)
       at com.google.crypto.tink.integration.android.AndroidKeystoreKmsClient.validateAead(AndroidKeystoreKmsClient.java:248)
       at com.google.crypto.tink.integration.android.AndroidKeystoreKmsClient.getAead(AndroidKeystoreKmsClient.java:165)
       at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewMasterKey(AndroidKeysetManager.java:267)
       at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:236)
       at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:123)
       at com.amplifyframework.core.store.EncryptedKeyValueRepository$sharedPreferences$2.invoke(EncryptedKeyValueRepository.kt:35)
       at com.amplifyframework.core.store.EncryptedKeyValueRepository$sharedPreferences$2.invoke(EncryptedKeyValueRepository.kt:34)
       at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
       at com.amplifyframework.core.store.EncryptedKeyValueRepository.getSharedPreferences$com_amplifyframework_core(EncryptedKeyValueRepository.kt:34)
       at com.amplifyframework.core.store.EncryptedKeyValueRepository.get(EncryptedKeyValueRepository.kt:56)
       at com.amplifyframework.auth.cognito.data.AWSCognitoAuthCredentialStore.retrieveCredential(AWSCognitoAuthCredentialStore.kt:63)
       at com.amplifyframework.auth.cognito.actions.CredentialStoreCognitoActions$loadCredentialStoreAction$$inlined$invoke$1.execute(Action.kt:70)
       at com.amplifyframework.statemachine.ConcurrentEffectExecutor$execute$1$1.invokeSuspend(ConcurrentEffectExecutor.kt:26)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt)

The linked and embedded framework 'shared.framework' is missing one or more architectures required by this target: arm64. (in target 'iosApp' from project 'iosApp')

Looks like Xcode is invoked for arm64 while the framework was build for X64:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target arm64-apple-ios13.2-simulator -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk -L/Users/mbonnin/git/kmm-sample/build/ios/Debug-iphonesimulator -F/Users/mbonnin/git/kmm-sample/build/ios/Debug-iphonesimulator -F/Users/mbonnin/git/kmm-sample/iosApp/../shared/build/xcode-frameworks -filelist /Users/mbonnin/git/kmm-sample/build/ios/iosApp.build/Debug-iphonesimulator/iosApp.build/Objects-normal/arm64/iosApp.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/mbonnin/git/kmm-sample/build/ios/iosApp.build/Debug-iphonesimulator/iosApp.build/Objects-normal/arm64/iosApp_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/mbonnin/git/kmm-sample/build/ios/iosApp.build/Debug-iphonesimulator/iosApp.build/Objects-normal/arm64/iosApp.swiftmodule -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/mbonnin/git/kmm-sample/build/ios/iosApp.build/Debug-iphonesimulator/iosApp.build/iosApp.app-Simulated.xcent -framework shared -Xlinker -dependency_info -Xlinker /Users/mbonnin/git/kmm-sample/build/ios/iosApp.build/Debug-iphonesimulator/iosApp.build/Objects-normal/arm64/iosApp_dependency_info.dat -o /Users/mbonnin/git/kmm-sample/build/ios/iosApp.build/Debug-iphonesimulator/iosApp.build/Objects-normal/arm64/Binary/iosApp
ld: warning: ignoring file /Users/mbonnin/git/kmm-sample/shared/build/xcode-frameworks/shared.framework/shared, building for iOS Simulator-arm64 but attempting to link with file built for iOS Simulator-x86_64
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_SharedGreeting", referenced from:
      objc-class-ref in ContentView.o
  "_OBJC_CLASS_$_SharedCalculatorCompanion", referenced from:
      objc-class-ref in ContentView.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is there a way I can tell XCode to build for the simulator? (I do have System.getenv("SDK_NAME") == "iphonesimulator")

IME_ACTION_DONE is possible with empty credential fields

If you go into the password field and hit done with keyboard you are logged in...

Possible solution:

setOnEditorActionListener { _, actionId, _ ->
                when {
                    actionId == EditorInfo.IME_ACTION_DONE && login.isEnabled -> {
                        loginViewModel.login(
                            email.text.toString(),
                            password.text.toString()
                        )
                    }
                }
                false
            }

Run Android Junit

Using this project as a base to understand how to run JUnit Android test within the shared Library: https://github.com/Kotlin/kmm-sample/blob/master/shared/src/androidTest/kotlin/com/jetbrains/kmm/shared/androidTest.kt

Cross-posting from Android Studio issue: https://issuetracker.google.com/issues/191287536
I'm not sure if it's a code issue (so a modification on this code base), or a IDE issue.

Goal: run with JUnit the tests with the Android configuration on the shared module.

Issue: the junit test folder is not recognized as such with Android, it seems to be override by an Android Connected test.

Symptoms:

1- "No Task Available"

NoTaskAvailable

by right-click on the folder, clicking on "Run test", it creates a configuration that does not work.

SetupTest

The issue seems to be that Android Studio doesn't recognised "kotlin" as a valid language for testing. By renaming the folder "kotlin" within the test to "java", it is now possible to run it.

2- Test run on device, not on JUnit

  • when started the test, it will try to run it by starting the emulator. It should instead run it on the JVM like any other android JUnit test. It's because the "Run/Debug configuration" is using a "Android Instrumented Tests" instead of "JUnit" configuration.
    By trying to manually setup a JUnit configuration, the module Android Test does not appear.

CreateConfiguration

By running the CLI "./gradlew :shared:tasks", I am missing some configurations (it should contains "androidTest" - Executes unit tests for target Android.):

Verification tasks
------------------
allTests - Runs the tests for all targets and create aggregated report
check - Runs all checks.
connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.
connectedCheck - Runs all device checks on currently connected devices.
connectedDebugAndroidTest - Installs and runs the tests for debug on connected devices.
deviceAndroidTest - Installs and runs instrumentation tests using all Device Providers.
deviceCheck - Runs all device checks using Device Providers and Test Servers.
iosX64Test - Executes Kotlin/Native unit tests for target iosX64.
lint - Runs lint on all variants.
lintDebug - Runs lint on the Debug build.
lintRelease - Runs lint on the Release build.
test - Run unit tests for all variants.
testDebugUnitTest - Run unit tests for the debug build.
testReleaseUnitTest - Run unit tests for the release build.

Build: AI-203.7717.56.2031.7435690, 202106072248, 

AI-203.7717.56.2031.7435690, JRE 11.0.10+0-b96-7281165x64 JetBrains s.r.o., OS Mac OS X(x86_64) v11.2.3, screens 3584.0x2240.0; Retina

AS: Arctic Fox | 2020.3.1 Beta 4; Kotlin plugin: 203-1.5.10-release-891-AS7717.8; Android Gradle Plugin: 4.0.1; Gradle: 6.5; Gradle JDK: version 11.0.10; NDK: from local.properties: (not specified), latest from SDK: (not found); LLDB: pinned revision 3.1 not found, latest from SDK: (package not found); CMake: from local.properties: (not specified), latest from SDK: (not found), from PATH: (not found)

Use MVVM in shared code

Hi, how use MVVM, Live Data/Mutable Live Data in shared code? I try add moko-mvvm plugin, but it not work.

Problem running iOS app

I have a problem running the app on iOS. I'm on master branch. It gives me the following error:

/Users/sheroznazhmudinov/Developer/kmm-networking-and-data-storage/iosApp/iosApp/ContentView.swift:2:8: error: no such module 'shared'
import shared
       ^

** BUILD FAILED **

I face no problem running the Android app.

Android Project Import Problem

I both tested on AndroidStudio 4.1.2 and KMM Plugin (0.2.0) and IntelliJ CE 2020.3.2, I have following problem:

  • "androidApp" module can not be imported properly. When I switch from "Project" view to "Android" view, I can not see the android module. "loading" text only.
  • I can not open "activity_main.xml" for design. When I switch from "Code" to "Design", "Loading" text appears only. If I validate the file I get the following error:

validation_error

I tried updating the both gradle and android gradle plugins to the latest one but it did not help.

However, the project compiles and runs in both android and ios.

Works fine on IOS, not working on Andorid - many issues

Hi

Is this sample supposed to work on Android as it is ?I am getting a range or errors. Before i list them, can you tell me what i need to do after checking out master ?

After i checked out master, i added local.properties with the SDK info and set the signing team in XCode and then it worked fine

On Android it has been much more complex and i haven't got it to work yet

Thanks

Keep classed from shared module

I have an enum in shared native code and I am using this enum to pass data between fragments using safe args. To make release build work I have to keep the enum. But if I am just adding -keep to proguard with full qualified package id doesn't work. So, how to keep classed from a shared native module?

Publishing "shared" module to maven local repository

Hello everyone

I am trying to publish the "shared" module to maven local repository to use it with others kmm projects. In original project I add some piece of codes in build.gradle.kts. Please, see the fork to more details.

plugins {
    .....
    id("maven-publish")
}
kotlin {
    android {
        publishLibraryVariants()
    }
    ......

    configure(listOf(targets["metadata"])) {
        mavenPublication {
            val targetPublication = this@mavenPublication
            tasks.withType<AbstractPublishToMaven>()
                .matching { it.publication == targetPublication }
                .all { onlyIf { findProperty("isMainHost") == "true" } }
        }
    }
}
afterEvaluate {
    publishing {
        publications {
            create<MavenPublication>("release") {
                groupId = "com.jetbrains"
                artifactId = "KmmSample"
                version = "1.0"
                from(components["release"])
            }
        }
    }
}

After add these lines code the "shared" module is published to maven local repository with :

./gradlew :shared:clean
./gradlew :shared:build
./gradlew :shared:publishToMavenLocal

The repository com.jetbrains:KmmSample:1.0 is created successfully. So I created another KMM project to test the library. Please, see the test library to more details.

The library com.jetbrains:KmmSample:1.0 is imported with no errors into androidApp module and androidMain from 'shared' module. However, the library is not imported into commonMain and iosMain from 'shared' module.

Can anyone help me with this problem? Maybe is missing some configuration and I do not the reason.

Thanks in advanced.

new mpp project creation guide

Hello, is there any guide, how to create this kind of project from scratch? I've tried to follow this https://github.com/JetBrains/kotlin-native/blob/master/MULTIPLATFORM.md but with no success especially wiring common/shared module as framework to new xcode project. Also I've seen different project structures, one with common module at root of project with three source sets for common, common-platform-ios, common-platform-android and the other one with three seperate modules for common, common-platform-ios, common-platform-android. Problem is, it is hard to find out which build.gradle settings and dependencies are for which source set.

Replace kotlin-platform-jvm with kotlin-platform-android

Hello,

This project is a great example but wouldn't it make more sense to use kotlin-platform-android to illustrate how to implement the common part with an Android Library directly, then using in an Android App Project (here AndroidApp)?

iOS real device building problem

After I run commands below:

cd iosApp
../gradlew -p ../greeting/ios build

And open iosApp.xcodeproj with Xcode, and install it into my iPhone 6, it fails with error:

ld: warning: ignoring file /Users/piasy/Library/Developer/Xcode/DerivedData/iosApp-aawmhzhlqvbsjubtqpnkmjdvqytl/Build/Products/Debug-iphoneos/Greeting.framework/Greeting, file was built for x86_64 which is not the architecture being linked (arm64): /Users/piasy/Library/Developer/Xcode/DerivedData/iosApp-aawmhzhlqvbsjubtqpnkmjdvqytl/Build/Products/Debug-iphoneos/Greeting.framework/Greeting
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_GreetingFactory", referenced from:
      objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The key point is that Xcode link against x64 Greeting.framework.

After I modify this line, change compileDebugIos_x64KotlinNative into compileDebugIos_arm64KotlinNative, it succeed.

So how could we solve this problem elegantly?

BTW, the iosApp Xcode project has another problem, it should disable bitcode, because the Greeting.framework disable it.

ERROR when build in ios

Screenshot 2023-09-11 at 23 42 28
when I clone this project. i can't run ios project app.

Xcode: 14.3.1

Thanks for the support

commonMain source files are not visible for the app module

I am working on KMP project and I have a problem with access to my shared module source files.

Inside the app module everything which is related to the commonMain source files (shared module) Android studio complains and says Unresolved reference: exampleVariableFromSharedModule and intellisence is also lost.

Strange thing is that, when I run the project, everything works fine and there is no compilation issues at all.

I'm trying to fix that issue almost the hole week.

tried:

  1. cleaning the project,
  2. invalidate & restart
  3. different versions of Kotlin.
  4. open the project in two different versions of android studio (4.1.1 & 4.2 preview) with no luck.

That is my build.gradle.kts if it can be a helpful

import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
  kotlin("multiplatform")
  kotlin("plugin.serialization")
  id("com.android.library")
  id("koin")
  id("com.squareup.sqldelight")
}

repositories {
  gradlePluginPortal()
  google()
  jcenter()
  mavenCentral()
  maven {
    url = uri("https://dl.bintray.com/kotlin/kotlin-eap")
  }
  maven {
    url = uri("https://dl.bintray.com/ekito/koin")
  }
}
kotlin {
  android()

  val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
    if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
      ::iosArm64
    else
      ::iosX64

  iOSTarget("ios") {
    binaries {
      framework {
        baseName = "core"
      }
    }
  }
  val coroutinesVersion = "1.4.2"
  val ktorVersion = "1.5.0"
  val serializationVersion = "1.0.0-RC"
  val koinVersion = "3.0.0-alpha-4"
  val sqlDelight = "1.4.4"

  sourceSets {

    val commonMain by getting {
      dependencies {
        implementation("io.ktor:ktor-client-core:$ktorVersion")
        implementation("io.ktor:ktor-client-serialization:$ktorVersion")

        implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
        implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion")
        implementation ("org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.1")

        implementation("com.squareup.sqldelight:runtime:$sqlDelight")
        // SqlDelight extension
        implementation("com.squareup.sqldelight:coroutines-extensions:$sqlDelight")
        implementation("com.squareup.sqldelight:android-paging-extensions:1.2.1")

        // Koin for Kotlin
        implementation("org.koin:koin-core:$koinVersion")
        //shared preferences
        implementation("com.russhwolf:multiplatform-settings-no-arg:0.6.3")
      }
    }
    val commonTest by getting {
      dependencies {
        implementation(kotlin("test-common"))
        implementation(kotlin("test-annotations-common"))
      }
    }
    val androidMain by getting {
      dependencies {
        implementation("androidx.core:core-ktx:1.3.2")
        implementation("io.ktor:ktor-client-android:$ktorVersion")
        implementation("com.squareup.sqldelight:android-driver:$sqlDelight")
      }
    }
    val androidTest by getting {
      dependencies {
        implementation(kotlin("test-junit"))
        implementation("junit:junit:4.12")
      }
    }
    val iosMain by getting {
      dependencies {
        implementation("io.ktor:ktor-client-ios:$ktorVersion")
        implementation("com.squareup.sqldelight:native-driver:$sqlDelight")
      }
    }

  
    val iosTest by getting
  }
}



android {
  compileSdkVersion(29)
  sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
  defaultConfig {
    minSdkVersion(23)
    targetSdkVersion(29)
    versionCode = 1
    versionName = "1.0"
  }
//  buildTypes {
//    getByName("release") {
//      isMinifyEnabled = false
//    }
//    create("staging") {
//    }
//  }
  compileOptions {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
  }
}
val packForXcode by tasks.creating(Sync::class) {
  group = "build"
  val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
  val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
  val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
  val framework =
    kotlin.targets.getByName<KotlinNativeTarget>("ios").binaries.getFramework(mode)
//    kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
  inputs.property("mode", mode)
  dependsOn(framework.linkTask)
  val targetDir = File(buildDir, "xcode-frameworks")
  from({ framework.outputDirectory })
  into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)


sqldelight {
  database("CoreDb") {
    packageName = "com.example.package.core.sqldelight"
    sourceFolders = listOf("sqldelight")
    dialect = "sqlite:3.24"
//    schemaOutputDirectory = file("build/dbs")
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.