m

    Miguel Fermin

    2 years ago
    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.
    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.
    Kris Wong

    Kris Wong

    2 years ago
    how did you specify the dependency in your build file?
    m

    Miguel Fermin

    2 years ago
    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
    Kris Wong

    Kris Wong

    2 years ago
    implementation means that the library is to be consumed within the project, not exported
    try api
    m

    Miguel Fermin

    2 years ago
    I tried this
    api project(path: ':mpp-lib-release')
    sync worked but still don't see the classes from the module
    Kris Wong

    Kris Wong

    2 years ago
    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

    2 years ago
    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 🙂
    mkojadinovic

    mkojadinovic

    2 years ago
    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:
    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

    2 years ago
    Thanks, I'll give this a shot
    Kris Wong

    Kris Wong

    2 years ago
    publishing will not have any affect on the generated artifact
    mkojadinovic

    mkojadinovic

    2 years ago
    true, but I had an issue that POM file wasn’t generated well and I was missing some dependencies in consumer app.