I've set it up a KN project running on android and...
# kotlin-native
g
I've set it up a KN project running on android and ios (building the framework from within the xcode) and it works pretty well except for testing. I'm trying to have a test folder for common, android e ios but when i run the common tests it gets the actual from the android env. If i create a kotlin native ios/android project from intelliJ itself the tests work but i can't make it generate new framework from within xcode, which i managed to do with the manual setup. In the thread is my build.gradle
Copy code
apply plugin: "org.jetbrains.kotlin.multiplatform"

kotlin {
    targets {
        //Xcode sets SDK_NAME environment variable - based on whether the
        //target device is a simulator or a real device, the preset should vary
        final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos")   \
                                ? presets.iosArm64 : presets.iosX64

        //outputKinds - FRAMEWORK would mean that the shared code would be exported as a FRAMEWORK
        // EXECUTABLE - produces a standalone executable that can be used to run as an app
        fromPreset(iOSTarget, 'ios') {
            binaries {
                framework('SharedCode')
            }
        }

        fromPreset(presets.jvm, 'android')
    }

    sourceSets {
        commonMain {
            dependencies {
                implementation kotlin('stdlib-common')
            }
        }
        commonTest {
            dependencies {
                implementation kotlin('test-common')
                implementation kotlin('test-annotations-common')
            }
        }
        androidMain {
            dependencies {
                implementation kotlin('stdlib')
            }
        }
        androidTest {
            dependencies {
                implementation kotlin('test')
                implementation kotlin('test-junit')
            }
        }
        iosMain {
        }
        iosTest {
        }
    }
}
I'm using a shared module in an Android application
s
Try adding:
Copy code
iosTest {
            dependsOn commonTest
        }
One thing I usually change about the android module is the preset it uses. When using jvm, it can't reference anything in the Android SDK. I usually change it to
fromPreset(presets.android, 'android')
and add in a
jvm()
target for fast running of tests from the command line.
g
Yeah, i was noticing that i'm not able to reference android sdk.
When i run my common test i get:
Copy code
org.junit.ComparisonFailure: 
Expected :Platform
Actual   :Hello from Android
Is it normal the common to use the expected for either one of the platforms? Also ios tests do not run at all
And when io try to use the
fromPreset(presets.android, 'android')
it fails with:
Extension with name 'android' does not exist.
Oh i think it's expected to get from either one of the platforms
s
If you change it to android you'll need to add in the
android { ... }
block with the standard params (compileSDKVersion, defaultConfig, etc) outside of the kotlin { } block.
Your ios tests should run from the command line. I don't think AS or IntelliJ support it yet. That may have changed recently with 1.3.40.
g
yeah, just saw you need create a task for it
oh ok, that was really helpful
thanks for all the info
👍 1