[英]Gradle lint & test build error - JAXBException and Invalid package reference in library
Today i was trying to add an Android project to CIRCLE CI where i'm running ./gradlew lint test as a check for builds to pass.今天我试图将一个 Android 项目添加到 CIRCLE CI,我正在运行 ./gradlew lint test 作为构建通过的检查。 The issue is that i got some annoying errors and i'm struggling from hours to solve them:问题是我遇到了一些烦人的错误,我正在努力解决这些问题:
on my local machine, i get: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
在我的本地机器上,我得到: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
and on CIRCLE CI the following error is thrown:在 CIRCLE CI 上抛出以下错误:
The first 3 errors (out of 10) were: /home/circleci/.gradle/caches/modules-2/files-2.1/javax.activation/activation/1.1.1/485de3a253e23f645037828c07f1d7f1af40763a/activation-1.1.1.jar: Error: Invalid package reference in library;前 3 个错误(共 10 个)是:/home/circleci/.gradle/caches/modules-2/files-2.1/javax.activation/activation/1.1.1/485de3a253e23f645037828c07f1d7f1af40763a/activation.jar:1.1Error : 库中的包引用无效; not included in Android: java.awt.datatransfer.未包含在 Android 中:java.awt.datatransfer。 Referenced from javax.activation.ActivationDataFlavor.引用自 javax.activation.ActivationDataFlavor。 [InvalidPackage] /home/circleci/.gradle/caches/modules-2/files-2.1/javax.activation/activation/1.1.1/485de3a253e23f645037828c07f1d7f1af40763a/activation-1.1.1.jar: Error: Invalid package reference in library; [InvalidPackage] /home/circleci/.gradle/caches/modules-2/files-2.1/javax.activation/activation/1.1.1/485de3a253e23f645037828c07f1d7f1af40763a/activation-1.1.1.jar包引用:库中的错误:InvalidPackage not included in Android: java.awt.event.未包含在 Android 中:java.awt.event。 Referenced from com.sun.activation.viewers.TextEditor.引用自 com.sun.activation.viewers.TextEditor。 [InvalidPackage] /home/circleci/.gradle/caches/modules-2/files-2.1/javax.activation/activation/1.1.1/485de3a253e23f645037828c07f1d7f1af40763a/activation-1.1.1.jar: Error: Invalid package reference in library; [InvalidPackage] /home/circleci/.gradle/caches/modules-2/files-2.1/javax.activation/activation/1.1.1/485de3a253e23f645037828c07f1d7f1af40763a/activation-1.1.1.jar包引用:库中的错误:InvalidPackage not included in Android: java.awt.未包含在 Android 中:java.awt。 Referenced from com.sun.activation.viewers.ImageViewer.引用自 com.sun.activation.viewers.ImageViewer。 [InvalidPackage] [无效包裹]
I am using databinding in my android project, together with livedata and androidx.我在我的 android 项目中使用数据绑定,以及 livedata 和 androidx。 I've been searching the web for hours and nothing helped me.我已经在网上搜索了几个小时,但没有任何帮助。 I tried to silence the errors with:我试图通过以下方式消除错误:
lintOptions { abortOnError true lintConfig file("lint.xml") }
and lint.xml:和 lint.xml:
<lint>
<issue id="InvalidPackage">
<ignore path="**/activation*.jar"/>
</issue>
</lint>
Thanks in advance for any help.在此先感谢您的帮助。 Please ask for more information if needed!如果需要,请询问更多信息!
@Gabi I was able to replicate the issue in a public github repo + circleci, and resolve it. @Gabi 我能够在公共 github repo + circleci 中复制该问题,并解决它。
Please see the following Public android-practice github repo commit history: https://github.com/ejparz/android-practice/commits/master请参阅以下公共 android-practice github repo 提交历史: https : //github.com/ejparz/android-practice/commits/master
As part of this commit I got the corresponding CircleCi build working properly.作为此提交的一部分,我使相应的 CircleCi 构建正常工作。
Commit : https://github.com/ejparz/android-practice/commit/b5f4b20a2adc3ef828153b39869f766ee7e9920e提交: https : //github.com/ejparz/android-practice/commit/b5f4b20a2adc3ef828153b39869f766ee7e9920e
Build : https://circleci.com/gh/ejparz/android-practice/6构建: https : //circleci.com/gh/ejparz/android-practice/6
Then I added an invalid package (javax.activation:activation), and got the same errors as you in the corresponding circleci build然后我添加了一个无效的包(javax.activation:activation),在相应的circleci build中得到和你一样的错误
Commit : https://github.com/ejparz/android-practice/commit/ca6f502170439e28cbcf269eac302369a282d7d0提交: https : //github.com/ejparz/android-practice/commit/ca6f502170439e28cbcf269eac302369a282d7d0
Build : https://circleci.com/gh/ejparz/android-practice/7构建: https : //circleci.com/gh/ejparz/android-practice/7
Notice the build has the same errors you report Error: Invalid package reference in library;请注意,构建具有与您报告的错误相同的错误Error: Invalid package reference in library; not included in Android: java.awt.datatransfer.未包含在 Android 中:java.awt.datatransfer。 Referenced from javax.activation.ActivationDataFlavor etc.引用自 javax.activation.ActivationDataFlavor等。
Then, I fix the error by adding a lint.xml file at the root of application module然后,我通过在应用程序模块的根目录添加一个 lint.xml 文件来修复错误
Commit : https://github.com/ejparz/android-practice/commit/7e9f7ca030370570e55c34201fd6f568e049279e提交: https : //github.com/ejparz/android-practice/commit/7e9f7ca030370570e55c34201fd6f568e049279e
Build : https://circleci.com/gh/ejparz/android-practice/8构建: https : //circleci.com/gh/ejparz/android-practice/8
The build now succeeds!现在构建成功!
Please Note that the location of the lint.xml file is very important.请注意 lint.xml 文件的位置非常重要。 It CANNOT go at root of project.它不能进入项目的根目录。 It must go at root of module (As indicated in this other SO post: Firestore: Invalid package reference in library )它必须位于模块的根目录(如其他 SO 帖子中所示: Firestore:库中的包引用无效)
Please let me know if this works for you.请让我知道这是否适合您。
This error is caused by your JDK version (A better explanation in this SO answer )此错误是由您的 JDK 版本引起的(此 SO答案中有更好的解释)
On a Mac you can try to use brew to install JDK8 which solves the problem.在 Mac 上,您可以尝试使用 brew 安装解决问题的 JDK8。
To do so:这样做:
brew tap adoptopenjdk/openjdk
to enable adopto open jdk formulas (The officials are no longer available).运行brew tap adoptopenjdk/openjdk
启用adapto open jdk 公式(官方已经没有了)。brew cask install adoptopenjdk/openjdk/adoptopenjdk8
to install open jdk 8运行brew cask install adoptopenjdk/openjdk/adoptopenjdk8
安装 open jdk 8brew install jenv
to Install jenv (Java version manager)运行brew install jenv
来安装 jenv(Java 版本管理器)echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
and echo 'eval "$(jenv init -)"' >> ~/.zshrc
if you use ZSH or echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
and echo 'eval "$(jenv init -)"' >> ~/.bash_profile
if you use BASH运行echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
and echo 'eval "$(jenv init -)"' >> ~/.zshrc
.zshrc 如果您使用 ZSH 或echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
and echo 'eval "$(jenv init -)"' >> ~/.bash_profile
如果你使用 BASHjenv add Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
to add jdk version 8运行jenv add Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
添加 jdk version 8jenv versions
to list your installed versions运行jenv versions
列出你安装的版本jenv global <name of version>
to change to another one运行jenv global <name of version>
更改为另一个Find out more about jenv in this website you can also configure java versions by folder instead of globally在此网站中了解有关 jenv 的更多信息,您还可以按文件夹而不是全局配置 java 版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.