I've set up a Kotlin multiplatform project. I have a shared project and an Android project. I've compiled the shared project and it creates .AAR and .Jar files with 1 method.
For easy syncing of changes, I've added the maven-publish plugin:
plugins {
id("maven-publish")
}
I generate my jars and aars and use publishToMavenLocal:
./gradlew build
./gradlew publishToMavenLocal
When I go into the local directory I indeed see my library:
/Users/{MY_USERNAME}/.m2/repository/mylibrary/nameOfMyLibrary/1.0/nameOfMyLibrary-1.0-kotlin-tooling-metadata.json
/Users/{MY_USERNAME}/.m2/repository/mylibrary/nameOfMyLibrary/1.0/nameOfMyLibrary-1.0-sources.jar
/Users/{MY_USERNAME}/.m2/repository/mylibrary/nameOfMyLibrary/1.0/nameOfMyLibrary-1.0.jar
/Users/{MY_USERNAME}/.m2/repository/mylibrary/nameOfMyLibrary/1.0/nameOfMyLibrary-1.0.module
/Users/{MY_USERNAME}/.m2/repository/mylibrary/nameOfMyLibrary/1.0/nameOfMyLibrary-1.0.pom
Then I open the Android project and add to project level build gradle:
buildscript {
repositories {
mavenLocal()
mavenCentral artifactUrls:["file:/home/{MY_USERNAME}/.m2/repository/"]
}
}
In settings.gradle I also add the maven Local:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenLocal()
google()
mavenCentral()
}
}
Then I include it in the build.gradle app level:
dependencies {
implementation "mylibrary:nameOfMyLibrary:1.0"
}
Then I sync Gradle and in my MainActivity I try to import a file from the library:
import com.mycompanyname.SomeClass
This doesn't work, the library is not found. Also when I try to import other repositories from that m2 directory, they are not found. Any ideas?
I've turned of my internet and then Android Studio asked:
"Do you want to enable Gradle offline mode".
But this also didn't help.