Referencing an android library from a java module

孤街浪徒 提交于 2019-12-23 12:35:21

问题


Long story short!

I want to add a Android library dependency to a Java module and it says

Warning:Ignoring dependency of module 'backtory-android-sdk' on module 'javasample'. Java modules cannot depend on Android modules

backtory-android-sdk doesn't have an Android related "compile dependency" (something like retrofit) and if there is a way to add dependency to backtory-android-sdk's "classes.jar" I assume it will be working. How can I do that?

Explaining the issue...

I'm working on an Android library that mostly do network request (backtory-android-sdk) and doesn't depend much on Android stuff so It could be initialized and used in a java project. I also have a Java module (a console project named javasample) for manual testing of the Android library (also used by other members of the team for some automated testing). Here's the confusion:

  • If I define backtory-android-sdk as Android library, I can't reference it from javasample, complaining that Warning:Ignoring dependency of module 'backtory-android-sdk' on module 'javasample'. Java modules cannot depend on Android modules
  • If I define it as a Java module, the previous problem resolves but our users at least have to add some manifest stuff manually (our SDK is currently an Android library module). Since almost all of our SDK users are Android developers this is not very desirable.

Since I know one could publish only source code of an Android library, I think its better sticking to Android library module and publish it in two type of AAR and JAR and then the problem reduces to referencing sources of backtory-android-sdk from javasample.


回答1:


This is because an Android module contains android components which will not work on a plain Java setup.

  • Perhaps your dependency needs to be inverted. Otherwise your main Java module will need to be updated to an Android module.

  • Alternatively if the android module does not do anything Android specific, make it a regular Java module.

  • The most likely scenario is that you need a 3rd module - an Android application which ties the two parts together



来源:https://stackoverflow.com/questions/46155960/referencing-an-android-library-from-a-java-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!