模块库Jar未在Android Studio的外部库中显示

bj0*_*bj0 10 android intellij-idea android-studio

我无法External Libraries在Android Studio中显示jar库.我正在尝试为此库添加javadoc,我在网上找到的唯一方法是右键单击库External Libraries并选择Library Properties....

项目结构是一个包含许多模块的树:

rootsdk / 
        main.jar
        main-javadoc.jar
        plugins /
                plugin1 / 
                        build.gradle
                        ...
                plugin2 /
                        build.gradle
                        ...
                ...
Run Code Online (Sandbox Code Playgroud)

依赖项在build.gradle文件中声明,如:

compileOnly files('../../main.jar')
Run Code Online (Sandbox Code Playgroud)

如果我打开各个目录plugin1,则依赖项会External Libraries正确显示.但是,如果我打开rootsdk项目,它就不会出现.所有模块都是从根项目中列出并编译的,我可以使用库中定义的类,但它不会出现在下面External Libraries,所以我不能为它添加javadoc.

奇怪的是一些插件使用其他库,但定义不同:

repositories {
    flatDir {
     dirs 'libs'
    }
}

...

implementation(name: 'core-debug', ext: 'aar')
Run Code Online (Sandbox Code Playgroud)

这些图书馆出现在External Libraries预期之下.

是否有东西缺少强制main.jar显示External Libraries,或者这是AS中的错误?

TWi*_*Rob 0

这是一件愚蠢的事情,但如果你将其设为 Ivy 或 Maven 存储库,它应该可以工作。files不。以下两个解决方案都应支持-sources-javadoc后缀。我认为 IDEA 只实现了来自存储库的工件解析,并没有考虑直接文件引用。

常春藤

repositories {
    def repoRoot = file(rootProject.projectDir)
    ivy {
        name = "local libs"
        url = repoRoot.toURI()
        patternLayout {
            artifact("[module](-[classifier]).[ext]")
        }
        metadataSources {
            artifact()
        }
    }
}
dependencies {
    // `local` group and version `0` are just a hack so Gradle dependency notation can be used.
    implementation("local:main:0")
    implementation("local:core-debug:0@aar")
}
Run Code Online (Sandbox Code Playgroud)

梅文

您可以执行与上面类似的操作,但存储库结构不太灵活。您需要移动 .jar/.aar 文件。我建议为它们创建一个文件夹(即使现在有一个)。在示例中我将其称为libs.

repositories {
    def repoRoot = file(rootProject.projectDir.resolve("libs"))
    exclusiveContent {
        // Work around
        // > Could not GET 'https://repo.gradle.org/gradle/libs-releases-local/local/main/0/main-0.pom'. Received status code 409 from server: Conflict
        // by not allowing Gradle to contact other repositories for "local" files.
        filter {
            includeGroup("local")
        }
        forRepository {
            maven {
                name = "local libs"
                url = repoRoot.toURI()
                metadataSources {
                    artifact()
                }
            }
        }
    }
}
dependencies {
    // `local` group and version `0` are just a hack so Gradle dependency notation can be used.
    implementation("local:main:0")
    implementation("local:core-debug:0@aar")
}
Run Code Online (Sandbox Code Playgroud)

错误消息会告诉您将其放置在哪里,例如:

* What went wrong:
Execution failed for task ':...'.
> Could not resolve all files for configuration ':...'.
   > Could not find local:main:0.
     Searched in the following locations:
       - file:/.../libs/local/main/0/main-0.jar
     Required by:
         project :...
   > Could not find local:core-debug:0.
     Searched in the following locations:
       - file:/.../libs/local/core-debug/0/core-debug-0.aar
     Required by:
         project :...

Run Code Online (Sandbox Code Playgroud)

请注意,虽然这更复杂,但也更灵活,因为您可以手写或下载 POM 文件,因此包含本地 JAR 文件的传递依赖项,metadataSources如果您的工件有 POM XML 文件,只需删除该块即可。

metadataSources

这个魔法值得一提(文档):

metadataSources {
    artifact()
}
Run Code Online (Sandbox Code Playgroud)

它告诉 Gradle,没有与存储库中的工件关联的元数据(POM 或 Ivy XML 文件),只有工件存在。如果没有这个,查找元数据就会失败。