-1

I have the same requirement as this post: same issue

As the author on the above issue said in the comment, I am also stuck in the same place. Any solution?

PS: I have to post this because I don't have enough stack overflow reputations yet to make comment on the same post and ask an author if he was able to find a solution.

  • If you're writing unit tests, those are not Android apps. They run on your PC. As such, they can't include Android libraries. The format is wrong, and the compiled bytecode inside is not compatible with the JDK. – Gabe Sechan Jan 22 '23 at 07:15

1 Answers1

1

Java modules can't depend on Android Modules, only Android Modules can depend on Java Modules, as stated in the linked questions error as well.

If you are building a module for testing, to be used in you app's unit tests, that module can be simply an Android Library momdule, doesn't need to be a Java Module. In an Application module (or Android Library module) you can have aar as test dependencies, like testImplementation "io.reactivex.rxjava2:rxandroid:2.0.1".

However, if your code under test actually interacts with Android SDK, you will need to mock those. In such case, first you will need to consider to just write AndroidTest instead. If it is important to be unit class, then you might want to look into using robolectric.

Gergely Hegedus
  • 482
  • 3
  • 9