2
votes

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

and on CIRCLE CI the following error is thrown:

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; not included in Android: java.awt.datatransfer. Referenced from 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; not included in Android: java.awt.event. Referenced from 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; not included in Android: java.awt. Referenced from com.sun.activation.viewers.ImageViewer. [InvalidPackage]

I am using databinding in my android project, together with livedata and 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>
<issue id="InvalidPackage">
    <ignore path="**/activation*.jar"/>
</issue>
</lint>

Thanks in advance for any help. Please ask for more information if needed!

2
It seems you have followed the other SO advice here to remove the error stackoverflow.com/questions/50159255/…. However, that post seems to indicate that the place you keep lint.xml is important (it should be at root of application module, not project). Can you plz share your project structure, and where that file is kept? - Parzie
Also, can you please try replaceing <ignore path="*/activation.jar"/> with <ignore path="*/javax.activation/activation/"/> Notice here we are more specific about the parent directories of activation ignore, and we're ignoring all files (not just jars) - Parzie
@Parzie i tried also with "*/javax.activation/activation/" and it's still not working. My lint.xml file location is project/app/lint.xml - Gabi
is your github repo public? i.e. can you share a link to it so I can clone it locally and test? - Parzie
Unfortunately it's a private repo at my organization - Gabi

2 Answers

0
votes

@Gabi I was able to replicate the issue in a public github repo + circleci, and resolve it.

Please see the following Public android-practice github repo commit history: https://github.com/ejparz/android-practice/commits/master

As part of this commit I got the corresponding CircleCi build working properly.

Commit: https://github.com/ejparz/android-practice/commit/b5f4b20a2adc3ef828153b39869f766ee7e9920e

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

Commit: https://github.com/ejparz/android-practice/commit/ca6f502170439e28cbcf269eac302369a282d7d0

Build: https://circleci.com/gh/ejparz/android-practice/7

Notice the build has the same errors you report Error: Invalid package reference in library; not included in Android: java.awt.datatransfer. Referenced from javax.activation.ActivationDataFlavor etc.


Then, I fix the error by adding a lint.xml file at the root of application module

Commit: https://github.com/ejparz/android-practice/commit/7e9f7ca030370570e55c34201fd6f568e049279e

Build: 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. 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)

Please let me know if this works for you.

0
votes

This error is caused by your JDK version (A better explanation in this SO answer )

On a Mac you can try to use brew to install JDK8 which solves the problem.

To do so:

  1. Install Brew from this website
  2. Run brew tap adoptopenjdk/openjdk to enable adopto open jdk formulas (The officials are no longer available).
  3. Run brew cask install adoptopenjdk/openjdk/adoptopenjdk8to install open jdk 8
  4. Run brew install jenv to Install jenv (Java version manager)
  5. Run 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
  6. Close and Open the console again
  7. Run jenv add Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home to add jdk version 8
  8. Run jenv versions to list your installed versions
  9. Run jenv global <name of version> to change to another one

Find out more about jenv in this website you can also configure java versions by folder instead of globally