https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
m

Miguel Fermin

12/11/2019, 9:46 PM
Hi everyone, I'm working on a native Android Library (aar) to make available to the Android UI team, who doesn't have access to the source code. I want to use a Kotlin multiplatform generated aar inside this library. I had followed the steps to add the main android library to an android app (to simulate what the UI team will have to do) as described here - https://developer.android.com/studio/projects/android-library, and it worked fine when it was just the main library. I then added the mpp generated aar to the main android library, following the same steps (https://developer.android.com/studio/projects/android-library) but the public classes aren't visible. I tried doing the same but using non-mpp libraries (aar), and I can at least see the nested libraries classes from the top level lib.
Copy code
app
	|
	|_ LibA 
			|
			|_ LibB (mpp)
Next thing I have in mind is trying to generate .jar libraries from Kotlin mpp and see if that works Any ideas would be highly appreciated.
k

Kris Wong

12/11/2019, 9:48 PM
how did you specify the dependency in your build file?
m

Miguel Fermin

12/11/2019, 9:50 PM
Copy code
dependencies {
    ...
    implementation project(path: ':mpp-lib-release')
}
Android Studio modified the settings.gradle and made a copy of the aar file
gradle sync doesn't give me any errors, but it doesn't recognize imports from the lib
k

Kris Wong

12/11/2019, 10:01 PM
implementation means that the library is to be consumed within the project, not exported
try api
m

Miguel Fermin

12/11/2019, 10:08 PM
I tried this
Copy code
api project(path: ':mpp-lib-release')
sync worked but still don't see the classes from the module
k

Kris Wong

12/11/2019, 10:11 PM
Gradle adds the dependency to the compile classpath and build output. When a module includes an 
api
 dependency, it's letting Gradle know that the module wants to transitively export that dependency to other modules, so that it's available to them at both runtime and compile time.
¯\_(ツ)_/¯
m

Miguel Fermin

12/11/2019, 10:16 PM
Thanks Kris, I haven't figured it out yet, but your answers were very helpful in pointing me to the right direction. I'll keep digging 🙂
m

mkojadinovic

12/12/2019, 8:08 AM
Hm, I am not sure that I understand well, but I had similar issue. First I used
com.jfrog.artifactory
plugin for publishing aar and pom file. Also, for Android library you have to do something like this:
Copy code
project('logger') {
    artifactoryPublish.dependsOn('build')
    publishing {
        publications {
            aar(MavenPublication) {
                groupId = 'com.wayfair.logger'
                artifactId = 'android-logger'
                version = '0.2-alpha'
                artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
                pom.withXml {
                    def dependencies = asNode().appendNode('dependencies')
                    configurations.implementation.allDependencies.each {
                        def dependency = dependencies.appendNode('dependency')
                        dependency.appendNode('groupId', it.group)
                        dependency.appendNode('artifactId', it.name)
                        dependency.appendNode('version', it.version)
                    }
                }
            }
        }
    }

    artifactoryPublish {
        publications(publishing.publications.aar)
    }
}
FYI: I also needed to add proguard rule
m

Miguel Fermin

12/12/2019, 12:13 PM
Thanks, I'll give this a shot
k

Kris Wong

12/12/2019, 2:14 PM
publishing will not have any affect on the generated artifact
m

mkojadinovic

12/17/2019, 9:28 AM
true, but I had an issue that POM file wasn’t generated well and I was missing some dependencies in consumer app.
8 Views