简体   繁体   English

创建Android库jar以与非Android项目一起使用

[英]Create Android library jar to work with non-Android project

I am working on a library that ideally will have a strictly-Java component and added functionality for Android-specific projects, with the intent to be most useful for Android apps, but also work with other Java apps. 我正在开发一个库,该库在理想情况下将具有严格的Java组件并为Android特定项目添加功能,以期对Android应用程序最有用,但也可以与其他Java应用程序一起使用。

But my question is: how should this be designed? 但是我的问题是:应该如何设计? I do not plan on needing resources, so I want to compile it into a JAR, but would I need to make two JARs, one of the Java stuff and another for the Android stuff? 我不打算使用资源,所以我想将其编译成一个JAR,但是我是否需要制作两个JAR,其中一个Java材质,另一个用于Android材质? Or would a Java-only application be able to use a single JAR so long as it does not use the Android components? 还是仅Java的应用程序只要不使用Android组件就能使用一个JAR?

If you make a library that uses pure java and does not use any android apis. 如果您制作的库使用纯Java,而不使用任何Android API。 It will work on both standard java and android java. 它可以在标准Java和android Java上运行。 However if the library uses any android apis it can't be used in a standard java project. 但是,如果该库使用任何Android API,则无法在标准Java项目中使用。

As far as I know, the JAR would be good for both types of aplications. 据我所知,JAR适用于两种类型的应用。 It seems to mee that both JARs (just Java and android) are totally identical and thus equally compatible. 似乎这两个JAR(仅Java和android)都是完全相同的,因此具有同等的兼容性。 If you don't use any of the android components, including Resources there should not be a problem at all. 如果您不使用任何Android组件(包括Resources则应该完全没有问题。

You should still check whether you depend on libraries which are available on android and any normal Java distribution or -if not- either tell the user to preinstall the depending libraries or ship them whitin your JAR package and build path. 您仍然应该检查是否依赖于android和任何常规Java发行版上可用的库,或者-告诉用户预安装依赖的库,或随您的JAR包和构建路径一起发货。 Be carefull not to use libraries which are not available on android because the user has no or really few options to install them on himself. 请注意不要使用在android上不可用的库,因为用户没有或只有很少的选择可以自己安装它们。

What I don't understand is why you think your library is more usefull to android developers. 我不明白的是为什么您认为您的库对android开发人员更有用。 I can not think of any example where this could happen. 我想不出任何可能发生这种情况的例子。 If the problem is really specific for android, you should consider developing the library android-only. 如果问题确实是特定于android的,则应考虑开发仅适用于android的库。 If the problem is more general the lib will be usefull to all developers that might come to this problem, not just android. 如果问题更笼统,那么lib对于所有可能遇到此问题的开发人员都是有用的,而不仅仅是android。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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