icerockdev / moko-resources

Resources access for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
1.07k stars 120 forks source link

AS can't import common module #110

Closed DmyMi closed 4 years ago

DmyMi commented 4 years ago

After upgrading moko-resources to 0.13.0 and kotlin 1.4.0 i get this error when doing gradle sync in AS:

Warning:<i><b>project ':presentation': Unable to build Kotlin project configuration</b>
Details: java.lang.reflect.InvocationTargetException: null
Caused by: java.lang.IllegalStateException: Couldn't resolve metadata artifact for ModuleDependencyIdentifier(groupId=dev.icerock.moko, moduleId=parcelize) in configuration ':presentation:iosArm64CompileKlibraries'</i>

And Android Studio doesn't import the common&ios parts of the module. so i loose all ide features for imports, completion, etc. for that module :( everything works fine when i remove the moko-resources dependency.

module's build.gradle.kts:

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

plugins {
    id("com.android.library")
    kotlin("multiplatform")
    kotlin("kapt")
    kotlin("android.extensions")
    id("dev.icerock.mobile.multiplatform-resources")
}

android {
    compileSdkVersion(Deps.Versions.compileSdk)
    buildToolsVersion(Deps.Versions.buildTools)

    defaultConfig {
        minSdkVersion(Deps.Versions.minSdk)
        targetSdkVersion(Deps.Versions.compileSdk)
        versionCode = 1
        versionName = "1.0"
        testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
    }

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

    sourceSets {
        getByName("main").java.srcDirs("src/androidMain/kotlin")
        getByName("main").res.srcDirs("src/androidMain/res")
        getByName("main").manifest.srcFile("src/androidMain/AndroidManifest.xml")
        getByName("androidTest").java.srcDirs("src/androidTest/kotlin")
    }
}

version = "1.0"

kotlin {
    ios() {
        binaries {
            framework {
                export(Deps.Kotlin.Multiplatform.napier)
            }
        }
    }

    android()

    sourceSets {
        val commonMain by getting {
            dependencies {
                // other deps
                api(Deps.Kotlin.Multiplatform.resources)
            }
        }
        val commonTest by getting {
            dependencies {
                // other deps
            }
        }
        val androidMain by getting {
            dependencies {
                // other deps
            }
        }
        val androidTest by getting {
            dependencies {
                // other deps
            }
        }

        val iosMain by getting {
            dependencies {
               // other deps
            }
        }
        val iosTest by getting
    }
}

multiplatformResources {
    multiplatformResourcesPackage = "my.package.presentation"
}

in gradle.properties i have:

kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
xcodeproj=ios/app.xcworkspace
Skeptick commented 4 years ago

Hello! I fixed this error by adding

api("dev.icerock.moko:parcelize:0.4.0")
api("dev.icerock.moko:graphics:0.4.0")

in commonMain dependencies.

Alex009 commented 4 years ago

hi, @DmyMi ! @Skeptick is right, on kotlin 1.4.0 now bug, which should be fixed in 1.4.10 https://youtrack.jetbrains.com/issue/KT-41083#focus=Comments-27-4365126.0-0

for now just add

commonMainImplementation("dev.icerock.moko:parcelize:0.4.0")
commonMainImplementation("dev.icerock.moko:graphics:0.4.0")
DmyMi commented 4 years ago

thank you @Skeptick @Alex009 ! it works