serializer issue in building ios project
See original GitHub issueHi, I know similar issue has been discussed here many times, I have gone through all of them for example https://github.com/Kotlin/kotlinx.serialization/issues/264 https://github.com/Kotlin/kotlinx.serialization/issues/231 and others, but for some reason I am not able to solve it.
I also can run my project ok for android, but when I build it for iOS, I get following error
src/commonMain/kotlin/data/Models/User.kt:3:16: error: unresolved reference: serialization
import kotlinx.serialization.SerialId
^
src/commonMain/kotlin/data/Models/User.kt:4:16: error: unresolved reference: serialization
import kotlinx.serialization.SerialName
^
src/commonMain/kotlin/data/Models/User.kt:5:16: error: unresolved reference: serialization
import kotlinx.serialization.Serializable
^
src/commonMain/kotlin/data/Models/User.kt:7:2: error: cannot access 'Serializable': it is internal in 'kotlin.io'
@Serializable
^
My code structure is as follow
Project -app -native -shared –androidMain –commonMain –iOSMain
My App: build.gradle looks like
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
defaultConfig {
applicationId "au.com.rhinocrm"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/common.kotlin_module'
exclude 'META-INF/ktor-http.kotlin_module'
exclude 'META-INF/kotlinx-io.kotlin_module'
exclude 'META-INF/atomicfu.kotlin_module'
exclude 'META-INF/ktor-utils.kotlin_module'
exclude 'META-INF/kotlinx-coroutines-io.kotlin_module'
exclude 'META-INF/ktor-client-json.kotlin_module'
exclude 'META-INF/ktor-client-logging.kotlin_module'
exclude 'META-INF/ktor-client-core.kotlin_module'
}
dataBinding {
enabled = true
}
tasks.lint.enabled = false
}
dependencies {
implementation project(':SharedLibrary')
implementation "com.github.bumptech.glide:glide:$glide_version"
kapt "com.github.bumptech.glide:compiler:$glide_version"
implementation 'com.android.support:multidex:1.0.3'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
implementation "io.ktor:ktor-client-okhttp:$ktor_version"
implementation "io.ktor:ktor-client-json-jvm:$ktor_version"
implementation "com.android.support:recyclerview-v7:$support_library_version"
implementation "com.android.support:design:$support_library_version"
implementation "com.android.support:cardview-v7:$support_library_version"
implementation "com.android.support:appcompat-v7:$support_library_version"
implementation "com.android.support:support-v4:$support_library_version"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
implementation 'androidx.core:core-ktx:1.1.0-alpha04'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
implementation "android.arch.lifecycle:extensions:$lifecycle_libraries"
implementation "android.arch.lifecycle:viewmodel:$lifecycle_libraries"
kapt "android.arch.lifecycle:compiler:$lifecycle_libraries"
implementation 'com.google.android.gms:play-services-auth:16.0.1'
// AWS Mobile SDK for Android
implementation('com.amazonaws:aws-android-sdk-mobile-client:2.6.+@aar') { transitive = true }
implementation('com.amazonaws:aws-android-sdk-auth-userpools:2.6.+@aar') { transitive = true }
implementation('com.amazonaws:aws-android-sdk-auth-ui:2.6.+@aar') { transitive = true }
// Google SignIn
implementation ('com.amazonaws:aws-android-sdk-auth-google:2.6.+@aar') { transitive = true }
//Facebook SignIn
implementation ('com.amazonaws:aws-android-sdk-auth-facebook:2.6.+@aar') { transitive = true }
// Dependency Injection
implementation "org.koin:koin-android:0.9.1"
implementation 'org.koin:koin-androidx-viewmodel:1.0.2'
}
and my shared folder build.gradle is, I have tried remove this plugins, tried few other things from other online resources but always fail on same thing… I have tried adding and removing implementation “org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version”
in iOS part but nothing has any effect, have tried invalidating caching, removing .idea and build folders. tried different version combinations
plugins {
id 'kotlin-multiplatform'
id 'kotlinx-serialization'
}
kotlin {
targets {
fromPreset(presets.jvm, 'android')
// Change to `presets.iosArm64` to deploy the app to iPhone
fromPreset(presets.iosX64, 'ios') {
compilations.main.outputKinds('FRAMEWORK')
}
}
sourceSets {
commonMain.dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-runtime:$serialization_version"
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-json:$ktor_version"
implementation "io.ktor:ktor-client-logging:$ktor_version"
}
androidMain.dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
implementation "io.ktor:ktor-client-json-jvm:$ktor_version"
implementation "io.ktor:ktor-client-logging-jvm:$ktor_version"
}
iosMain.dependencies {
implementation "io.ktor:ktor-client-ios:$ktor_version"
implementation "io.ktor:ktor-client-core-ios:1.0.1"
implementation "io.ktor:ktor-client-json-ios:0.9.5"
}
}
}
// workaround for https://youtrack.jetbrains.com/issue/KT-27170
configurations {
compileClasspath
}
task packForXCode(type: Sync) {
final File frameworkDir = new File(buildDir, "xcode-frameworks")
final String mode = project.findProperty("XCODE_CONFIGURATION")?.toUpperCase() ?: 'DEBUG'
inputs.property "mode", mode
dependsOn kotlin.targets.ios.compilations.main.linkTaskName("FRAMEWORK", mode)
from { kotlin.targets.ios.compilations.main.getBinary("FRAMEWORK", mode).parentFile }
into frameworkDir
doLast {
new File(frameworkDir, 'gradlew').with {
text = "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$@\n"
setExecutable(true)
}
}
}
tasks.build.dependsOn packForXCode
inside setting.gralde file also tried commenting and uncommenting Gradle_metada part…
pluginManagement {
resolutionStrategy {
eachPlugin {
if (requested.id.id == "kotlin-multiplatform") {
useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
}
if (requested.id.id == "kotlinx-serialization") {
useModule("org.jetbrains.kotlin:kotlin-serialization:${requested.version}")
}
}
}
}
//enableFeaturePreview("GRADLE_METADATA")
include ':app', ':SharedLibrary'
although my understanding of entire Gradle build process is not expert level but I have tried all solutions available online, anything that made sense but still same error for iOS only.
Issue Analytics
- State:
- Created 5 years ago
- Comments:19 (6 by maintainers)
Top GitHub Comments
Hi!
First of all, you need to uncomment the line
enableFeaturePreview("GRADLE_METADATA")
– it helps Gradle search for Native artifacts.Secondly, in
commonMain.dependencies
you need to haveimplementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"
, iniosMain.dependencies
you need to haveimplementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"
, inandroid.main
–implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
Hope this helps.