icerockdev / moko-resources

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

Getting Unresolved reference: androidMainApi #398

Closed saravr closed 1 year ago

saravr commented 1 year ago

I followed the instructions in the README for my KMM project but got this unresolved reference error. What am I missing?

buildscript {
    dependencies {
        classpath("dev.icerock.moko:resources-generator:0.20.1")
    }
}

plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    id("com.android.library")
    id("dev.icerock.mobile.multiplatform-resources")
}
kotlin {
...
}
android {
...
}
multiplatformResources {
    multiplatformResourcesPackage = "com.example.mylib" // required
    multiplatformResourcesClassName = "SharedRes" // optional, default MR
    iosBaseLocalizationRegion = "en" // optional, default "en"
    multiplatformResourcesSourceSet = "commonClientMain"  // optional, default "commonMain"
}

dependencies {
    commonMainApi("dev.icerock.moko:resources:0.20.1")
    androidMainApi("dev.icerock.moko:resources-compose:0.20.1") // <<-- Unresolved reference: androidMainApi
    commonTestImplementation("dev.icerock.moko:resources-test:0.20.1")
}

Android Gradle Plugin version 7.3.1

Alex009 commented 1 year ago

use

"androidMainApi"("dev.icerock.moko:resources-compose:0.20.1")

or add dependency in kotlin source set block:

kotlin {
    sourceSets {
        val androidMain by getting {
            api("dev.icerock.moko:resources-compose:0.20.1")
        }
    }
}
saravr commented 1 year ago

@Alex009 thanks it worked

KiraResari commented 1 year ago

It's not working for me either

If I change it to "androidMainApi"("dev.icerock.moko:resources-compose:$mokoResourcesVersion"), I get this error:

Configuration with name 'androidMainApi' not found.

If I try it with:

        val androidMain by getting {
            api("dev.icerock.moko:resources-compose:0.20.1")
        }

...then I get this error:

e: E:\projects\ceal-chronicler\shared-ui\build.gradle.kts:30:5: Unresolved reference: androidMainApi

How do I correctly use this?

I've got a branch here where I'm trying to get this to work:

https://github.com/KiraResari/ceal-chronicler/tree/moko-resources

I've put the code for root build.gradle into the surface build.gradle.kts (which for me is also the project build gradle), and the code for project build.gradle into the shared-ui/build.gradle.kts

muhrifqii commented 1 year ago

I also encounter same issue like @KiraResari when building the project

Alex009 commented 1 year ago

@KiraResari you can depend from commonMain because you have only android & jvm targets. https://github.com/KiraResari/ceal-chronicler/pull/1