9

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.

Alireza Farahani
  • 2,238
  • 3
  • 30
  • 54

1 Answers1

6

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

Nick Cardoso
  • 20,807
  • 14
  • 73
  • 124
  • Until recently, I had a `backtory-java-sdk` module, and `backtory-android-module` and everything was good, but since you can publish a android library in Jar format I wondered is two separating to two module necessary? – Alireza Farahani Sep 11 '17 at 12:47
  • I'm not sure, but if it is not Android related, why does it need to be an Android module? (you mentioned it was safe to use because not using android specifics). Also, If the android module does something more on top of the java module, it seems like android should import java (invert dependency) – Nick Cardoso Sep 11 '17 at 12:49