2

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!

Gabi
  • 667
  • 1
  • 7
  • 17
  • It seems you have followed the other SO advice here to remove the error https://stackoverflow.com/questions/50159255/firestore-invalid-package-reference-in-library. 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 Jul 29 '19 at 19:24
  • Also, can you please try replaceing with Notice here we are more specific about the parent directories of activation ignore, and we're ignoring all files (not just jars) – Parzie Jul 29 '19 at 19:26
  • @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 Jul 30 '19 at 13:35
  • is your github repo public? i.e. can you share a link to it so I can clone it locally and test? – Parzie Jul 30 '19 at 14:03
  • Unfortunately it's a private repo at my organization – Gabi Jul 30 '19 at 14:12
  • Ok no problem, I'm going to try to replicate your issue in a minimal android project (in a public github repo + circleci) and will get back to you later today – Parzie Jul 30 '19 at 14:19
  • I suggest to use DataBinding and a BindingAdapter in your project to easily reproduce the error – Gabi Jul 30 '19 at 14:39

2 Answers2

0

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

Parzie
  • 210
  • 1
  • 12
  • I followed your advices and my lint.xml file was set up correctly. I have managed to run `./gradlew lint test` locally with success by setting `org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home` in project/gradle.properties so the wrapper will use the same JDK as Android Studio. But here is another problem, how do I configure this to run on CIRCLE CI? because this path only works on my machine – Gabi Jul 31 '19 at 06:12
  • I updated the circle image to `circleci/android:api-29` and i managed to pass the build. Thanks for helping me! – Gabi Jul 31 '19 at 06:53
0

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

Brahyam
  • 311
  • 2
  • 4