无法解析从本地源模块构建的本地AAR [英] Failed to resolve local AAR built from local source module

查看:111
本文介绍了无法解析从本地源模块构建的本地AAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个库模块,希望将其作为AAR依赖项包含在示例应用程序中:

I have a library module that I want to include as an AAR dependency into a sample app:

:my-library
:sample-app

因此,在sample/build.gradle中,我执行以下操作:

So in sample/build.gradle, I do the following:

repositories {
    flatDir {
        dirs "../my-library/build/outputs/aar" 
    }
}

// I have different flavors that specify whether to use the source or binary (aar) dependency

flavorDimensions "SOURCE_OR_BINARY"
    productFlavors {
        source { }
        binary { }
}

dependencies {
    sourceImplementation project(':my-library')
    binaryImplementation(name: 'my-library-release', ext: 'aar') // <-- this line fails with error
}

tasks.whenTaskAdded { task ->
    def taskName = task.name.toLowerCase()
    if (taskName.toLowerCase().contains("binary")) {
        // Prepare libs as binaries
        task.dependsOn ('my-library:assembleRelease')
    }
}

在命令行上与./gradlew一起使用时效果很好,但是Android Studio在gradle同步期间报告了Failed to resolve: :my-library-release:.如果我在命令行上执行./gradlew assemble然后同步Android Studio,则AS Gradle同步成功.

This works fine with ./gradlew on the command line, but Android Studio reports a Failed to resolve: :my-library-release: during gradle sync. If I do a ./gradlew assemble on the command line, then sync Android Studio, the the AS Gradle sync succeeds.

问题与binaryImplementation(name: 'my-library-release', ext: 'aar')的计时有关.当执行Gradle Sync时,aar尚不存在,因为尚未构建.

The issue has to do with the timing of binaryImplementation(name: 'my-library-release', ext: 'aar'). When Gradle Sync is executed, the aar does not exist yet because it has yet to be built.

是否有更好的方法来避免Failed to resolve Android Studio Gradle同步错误?

Is there a better way to do this that will avoid the Failed to resolve Android Studio Gradle sync error?

推荐答案

可以在此处找到答案-公开具有该AAR的配置,并在下游使用该配置

The answer can be found here - expose a configuration with that AAR, and consume that configuration downstream

https://docs.gradle.org/current/userguide/cross_project_publications.html

这篇关于无法解析从本地源模块构建的本地AAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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