从java模块引用一个android库 [英] Referencing an android library from a java module

查看:464
本文介绍了从java模块引用一个android库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

长话短说



我想将一个Android库依赖项添加到Java模块,并且它说



< blockquote>

警告:忽略模块'javasample'上模块'backtory-android-sdk'的依赖关系。 Java模块不能依赖于Android模块


backtory-android-sdk doesn' t有一个Android相关的编译依赖(类似retrofit),并且如果有一种方法可以添加依赖到 backtory-android-sdk 的classes.jar假定它会工作。我该怎么做?



解释问题...



我正在研究Android库主要做网络请求( backtory-android-sdk ),并且不依赖于Android的东西,所以它可以被初始化并用在一个java项目中。我还有一个Java模块(一个名为 javasample 的控制台项目),用于手动测试Android库(也被团队的其他成员用于一些自动化测试)。这里有一些困惑:


  • 如果我将 backtory-android-sdk 定义为Android库,我无法从> javasample 引用它,抱怨警告:忽略模块'javasample'上模块'backtory-android-sdk'的依赖关系。 Java模块不能依赖于Android模块

  • 如果我将其定义为Java模块,则前面的问题会解决,但我们的用户至少必须手动添加一些清单资料(我们的SDK目前是Android库模块)。由于我们几乎所有的SDK用户都是Android开发人员,所以这不是很理想。



因为我知道只能发布一个源代码Android库,我认为它更好地坚持Android库模块,并将它发布为两种类型的AAR和JAR,然后问题简化为引用源自 backtory-android-sdk 的来源 javasample

解决方案

这是因为一个Android模块包含的android组件不能用于普通的Java设置。


  • 也许您的依赖关系需要反转。否则,您的主要Java模块将需要更新到Android模块。

  • 另外,如果android模块没有执行任何Android特定操作,使其成为一个普通的Java模块
  • 最可能的情况是您需要第三个模块 - 一个Android应用程序将两部分连接在一起



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.

解决方案

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

这篇关于从java模块引用一个android库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆