简体   繁体   中英

Use an Android Library (AAR) as dependency for a Java (Jar) Project with Gradle?

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM