Hi, I would like to add KMM module into existing p...
# multiplatform
m
Hi, I would like to add KMM module into existing project. After adding new module there is missing dependecy, so I added maven jitpack.io. When I start gradle sync I get error: "Could not find: kotlin-native-prebuild-macou-aarch64:1.8.10". I have also tried it on linux and similar error occured. How can I solve it?
x
I think you can't publish kotlin Multiplatform libraries to jitpack - as they don't handle kotlin metadata correctly
m
I don't want to publish anything. just adding new KMM module to my app
x
Which kmm module is this? Is this something public?
m
no, I want to create my own module inside app for network communication
x
If it is submodule in the same project, you should be able to include it as a dependency
Copy code
implementation(project(":module-name")
How are you currently adding your module?
m
I have created new android application in Android Studio. Now I create new module and choose KMM module. Afte pressing finish I get error: Build was configured to prefer setting repositories over project repository 'ivy' was added by build file .... After that I changed setting.gradle repositoryMode to RepositoryMode.PREFFER_SETTINGS and added the repositore jitpack.io. Now when I would like to sync gradle I get this error which I mentioned at the beggining with prebuild for mac
m
Are you on a mac device? you can only build for apple on apple devices
m
yes, I am on mac
but I would like to use only Android for now
m
then I'm not sure why you added a mac target (which is why kotlin for mac is being fetched I suppose). you can always remove it in the build.gradle files.but without more information or code this is as far as I dare go troubleshooting.
x
Can you share how your
build.gradle
looks like for the project and each of the modules? Looks like it is misconfigured somewhere
m
this mac is there because I am working on mac, I have tried it also with linux and the linux dependecy was missing, something like kotlin-native-prebuild-linux-x64:1.8.10
build.gradle,settings.gradle
x
Can you try replacing your
dependencyResolutionManagement
with this?
Copy code
dependencyResolutionManagement { 
 repositories { 
     google() 
     mavenCentral() 
   } 
 }
}
m
It is downloading the prebuild now. Thank you. But this was generated code from KMM plugin, so not really sure why it happen
I had to remove unit tests, but thats ok. Hopefully find a way how can I test the KMM code
x
Yeah i think you might've have added that jitpack repository for a library that you are using in your Android app, you should able to add that back in if you want but don't think you need this
Copy code
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
Not sure what
RepositoriesMode.PREFER_SETTINGS
actually does, but that seems to break the order of how the dependencies are looked up from each repository
m
Do you know what framework can I use for testing?
x
Unit testing? Or Instrumentation testing?
m
unit, but instrumental will be later, so I would appreciate anything
x
If it is a Multiplatform module, use kotlinx.test
Here's some examples on how I set this up for my Multiplatform library
Kotlin.test is like JUnit, but you can choose which platform you want to run your unit tests on
a
the Kotlin Multiplatform plugin doesn't work out-of-the box with
dependencyResolutionManagement
yet https://youtrack.jetbrains.com/issue/KT-51379 You can add the repositories manually though https://github.com/Kantis/ks3/blob/7ae763fc9fac4cfab63c153261b281c6066d5c8f/build-logic/repositories.gradle.kts#L37-L65
j
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
just tells gradle to use the repositories defined in settings.gradle.kts in
dependencyResolutionManagement
preferably over a
repositories
block defined in a specific project's build.gradle.kts. It's a newer gradle feature. You can use the older method to define repositories for all projects, without forcing projects to not be able to add their own repositories by removing the
dependencyResolutionManagement
block in settings.gradle.kts and adding them under
Copy code
allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url '<https://jitpack.io|https://jitpack.io>' }
    }
}
in your top-level build.gradle.kts.
124 Views