Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Plugin 3.0.1 AAR transitive dependency missing [duplicate]

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 the included aar file has all dependencies included, but it hasn't.

When you do

git clone https://github.com/hannesa2/aar_dependency
./gradlew clean assembleDebug

means

dependencies {
    api project(':mylibrary')

it works properly.

But when I use insted of lib-module the previous generated *.aar file as dependency

 dependencies {
    api 'com.example.my.mylibrary:mylibrary-debug@aar'

(in demo app just do)

git checkout with_aar
./gradlew clean assembleDebug

I run into this

Task :app:transformClassesWithDesugarForDebug Exception in thread "main" java.lang.TypeNotPresentException: Type io.reactivex.ObservableTransformer not present at sun.invoke.util.BytecodeDescriptor.parseSig(BytecodeDescriptor.java:85) at sun.invoke.util.BytecodeDescriptor.parseMethod(BytecodeDescriptor.java:63) at sun.invoke.util.BytecodeDescriptor.parseMethod(BytecodeDescriptor.java:41) at java.lang.invoke.MethodType.fromMethodDescriptorString(MethodType.java:1067) at com.google.devtools.build.android.desugar.LambdaDesugaring$InvokedynamicRewriter.visitInvokeDynamicInsn(LambdaDesugaring.java:399) at org.objectweb.asm.MethodVisitor.visitInvokeDynamicInsn(Unknown Source) at org.objectweb.asm.MethodVisitor.visitInvokeDynamicInsn(Unknown Source)

Because I ordinary run into this with uploading the aar artifacts into our company Maven Nexus, I created this demo-repo to show exactly what's wrong. In demo app or using Maven I see the same issue.

Does someone knows what I did wrong ?

like image 455
hannes ach Avatar asked Oct 07 '17 10:10

hannes ach


People also ask

How does Gradle resolve transitive dependencies?

Transitive dependencyBy default, Gradle resolves transitive dependencies automatically. The version selection for transitive dependencies can be influenced by declaring dependency constraints.

What is transitive false in Gradle?

If you set transitive=false, then the io. fabric. sdk. android. Fabric class will not be found at compile time.

What is testImplementation in Gradle?

For example the testImplementation configuration extends the implementation configuration. The configuration hierarchy has a practical purpose: compiling tests requires the dependencies of the source code under test on top of the dependencies needed write the test class.

How do I add a dependency in Gradle?

To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build.gradle file.


1 Answers

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"
like image 79
hannes ach Avatar answered Sep 29 '22 10:09

hannes ach