Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing an android library from a java module

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.

like image 836
Alireza Farahani Avatar asked Sep 11 '17 12:09

Alireza Farahani


1 Answers

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

like image 95
Nick Cardoso Avatar answered Nov 09 '22 01:11

Nick Cardoso