Use an aar library cause missing dependencies using api in Gradle 4.x

后端 未结 1 1526
后悔当初
后悔当初 2020-12-01 22:48

When I build an app with a *.aar file instead of the module with Gradle 4.x and following the docu concerning implements and api, I expect using api

相关标签:
1条回答
  • 2020-12-01 23:02

    I was able to solve it. The main issue was Android O with Gradle 4.x using api

    dependencies {
        api 'com.squareup.okhttp3:logging-interceptor:3.4.1'
        api "io.reactivex.rxjava2:rxandroid:$versions.libs.rxAndroid"
    

    Most answers are concerning something like this

    publishing {
        publications {
            mipartner(MavenPublication) {
                groupId '...'
                artifactId '..'
                version 1.0
                artifact "$buildDir/outputs/aar/myLib-release.aar"
    
                //generate pom nodes for dependencies
                pom.withXml {
                    def dependenciesNode = asNode().appendNode('dependencies')
                    configurations.compile.allDependencies.each { dependency ->
                        def dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('groupId', dependency.group)
                        dependencyNode.appendNode('artifactId', dependency.name)
                        dependencyNode.appendNode('version', dependency.version)
                    }
                }
            }
        }
    
        repositories{
            maven {
                url "https://some.url.com"
            }
        }
    }
    

    but here in the resulting *.pom there are no dependencies included, after change this line to api the dependencies are included in deployed pom !

    configurations.api.allDependencies.each { dependency ->
    

    after this you can easily consume the aar file

    dependencies {
        api "com.mylib.net:mylib:1.0"
    
    0 讨论(0)
提交回复
热议问题