gpt4 book ai didi

android - 多模块项目中的 Javadoc 生成 "error package does not exist"

转载 作者:太空宇宙 更新时间:2023-11-03 11:38:58 27 4
gpt4 key购买 nike

我需要通过 Bintray 将我的库(多模块项目)上传到 sonatype 存储库。因此我需要为每个模块单独生成 Javadoc。

首先我遇到了这些类似问题中的问题

Android Studio Javadoc: Cannot find symbol

Gradle Javadoc fails with “error: package … does not exist”

来自第一个question中的解决方案,我可以解析我从第三方库(retrofit2,gson)和 @NonNull 使用的类注释错误。

但在我的例子中,我的一个模块 ( Lib2 ) 依赖于另一个模块 ( Lib1 )。

Lib2 生成 Javadoc 时模块,它的警告 package does not exist & cannot find symbol对于另一个模块的类(Lib1)。

并且两个模块都报告package does not exist Android 支持和设计库错误。

import <packagename>.R;报告 cannot find symbol

我的 Javadoc 生成任务

task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.source
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
ext.androidJar ="${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath += files(ext.androidJar)
project.android.libraryVariants.all { variant ->
classpath += files(variant.javaCompile.classpath.files)
}
}

Lib1 中的依赖项 build.gradle

compile rootProject.appcompat
compile rootProject.design
compile rootProject.retrofit2
compile rootProject.support
compile rootProject.gsonConverter
compile rootProject.httpLogInterceptor
compile rootProject.universalImageLoader

Lib2 中的依赖项 build.gradle

compile project(':core')
compile rootProject.appcompat
compile rootProject.design
compile rootProject.retrofit2
compile rootProject.support
compile rootProject.cardview

我试过了

task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

afterEvaluate {
androidJavadocs.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath
}

我的整个gradle-mvn-push.gradle

apply plugin: 'maven'
apply plugin: 'com.jfrog.bintray'
// Declaring variables

afterEvaluate { project ->
bintray {
user = bin_user
key = bin_key
configurations = ['archives']
publish = true
dryRun = false
pkg {
repo = REPO
name = POM_ARTIFACT_ID
userOrg = USER_ORG
desc = POM_DESCRIPTION
websiteUrl = POM_URL
vcsUrl = GIT_URL
licenses = ['Apache-2.0']
version {
name = VERSION_NAME
vcsTag = VERSION_NAME
gpg {
sign = true
try {
passphrase = PASS_PHRASE
} catch (Exception ignored) {
println 'Failed to find credentials. GPG sign disabled'
}
}
}
}
}

if (project.getPlugins().hasPlugin('com.android.application') ||
project.getPlugins().hasPlugin('com.android.library')) {
task install(type: Upload, dependsOn: assemble) {
repositories.mavenInstaller {
configuration = configurations.archives

pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME

pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL

scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}

licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}

developers {
developer {
id pom_developer_id
name pom_developer_name
}
}

}

pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')

//Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.compile.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}

task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.source
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
ext.androidJar ="${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath += files(ext.androidJar)
project.android.libraryVariants.all { variant ->
classpath += files(variant.javaCompile.classpath.files)
}
}

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}

task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.source
}


} else {
install {
repositories.mavenInstaller {
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME

pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL

scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}

licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}

developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}

task sourcesJar(type: Jar, dependsOn:classes) {
classifier = 'sources'
from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn:javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
}

if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
}

artifacts {
if (project.getPlugins().hasPlugin('com.android.application') ||
project.getPlugins().hasPlugin('com.android.library')) {
archives androidSourcesJar
archives androidJavadocsJar
} else {
archives sourcesJar
archives javadocJar
}
}
}

最佳答案

我使用下面的代码 fragment 解决了这个问题

task androidJavadocs(type: Javadoc, dependsOn: 'assembleRelease') {
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
android.libraryVariants.all { variant ->
if (variant.name == 'release') {
owner.classpath += variant.javaCompile.classpath
}
}
source = android.sourceSets.main.java.srcDirs
exclude '**/R.html', '**/R.*.html', '**/index.html'
}

但还是import <packagename>.R;报告 cannot find symbol .

引用资料:

Adventures with Javadocs, part 2(Introducing Android Framework Classes)

Adventures with Javadocs, part 3 (Introducing Classes From Third Party Dependencies)

关于android - 多模块项目中的 Javadoc 生成 "error package does not exist",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41076271/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com