在Gradle 4.x中使用AAR库导致使用API​​缺少依赖项 [英] Use an aar library cause missing dependencies using api in Gradle 4.x

查看:438
本文介绍了在Gradle 4.x中使用AAR库导致使用API​​缺少依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用* .aar文件而不是Gradle 4.x构建模块的应用程序时,并遵循

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.

这样做的时候

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

表示

dependencies {
    api project(':mylibrary')

它正常工作.

但是当我使用lib-module的insted时,先前生成的* .aar文件作为依赖项

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

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

(在演示应用中可以做到)

git checkout with_aar
./gradlew clean assembleDebug

我碰到了

任务:app:transformClassesWithDesugarForDebug 线程主"中的异常java.lang.TypeNotPresentException:类型io.reactivex.ObservableTransformer不存在 在sun.invoke.util.BytecodeDescriptor.parseSig(BytecodeDescriptor.java:85) 在sun.invoke.util.BytecodeDescriptor.parseMethod(BytecodeDescriptor.java:63) 在sun.invoke.util.BytecodeDescriptor.parseMethod(BytecodeDescriptor.java:41) 在java.lang.invoke.MethodType.fromMethodDescriptorString(MethodType.java:1067) 在com.google.devtools.build.android.desugar.LambdaDesugaring $ InvokedynamicRewriter.visitInvokeDynamicInsn(LambdaDesugaring.java:399) 在org.objectweb.asm.MethodVisitor.visitInvokeDynamicInsn(来源不明) 在org.objectweb.asm.MethodVisitor.visitInvokeDynamicInsn(未知来源)

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)

因为我在将aar工件上传到我们公司的Maven Nexus时遇到了这种情况,所以我创建了 demo-repo 准确显示出什么问题.在演示应用程序或使用Maven时,我会看到相同的问题.

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.

有人知道我做错了吗?

推荐答案

我能够解决它.主要问题是使用 api

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"
        }
    }
}

,但是在生成的 *.pom 中没有包含依赖项,将此行更改为 api 后,这些依赖项将包含在部署的pom中!

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 ->

在此之后,您可以轻松使用aar文件

after this you can easily consume the aar file

dependencies {
    api "com.mylib.net:mylib:1.0"

这篇关于在Gradle 4.x中使用AAR库导致使用API​​缺少依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆