How to distribute an Android Library

别等时光非礼了梦想. 提交于 2019-12-05 01:40:55

问题


I've been spinning a jar for android library project and including this jar in my other apps. But on developer.android.com, I see this statement that I can't distribute a library in a jar:

  • You cannot export a library project to a JAR file

A library cannot be distributed as a binary file (such as a JAR file). This will be added in a future version of the SDK Tools.

I really don't understand what does that mean.


回答1:


It is possible to create an Android library project that does not include source code. The limitations are:

  • You still have to ship the resources.

  • You have to rewrite your code to avoid using R. values, as they will be wrong. You will have to look up all resource IDs using getResources().getIdentifier() and/or reflection.

I have the instructions in The Busy Coder's Guide to Advanced Android Development (http://commonsware.com/AdvAndroid), though the instructions are new enough that none of my free versions have them. Quoting some of the instructions from the current edition:

"You can create a binary-only library project via the following steps:

  1. Create an Android library project, with your source code and such – this is your master project, from which you will create a version of the library project for distribution.

  2. Compile the Java source (e.g., ant compile) and turn it into a JAR file

  3. Create a distribution Android library project, with the same resources as the master library project, but no source code
  4. Put the JAR file in the distribution Android library project's libs/ directory

The resulting distribution Android library project will have everything a main project will need, just without the source code."

Personally, I'd just wait a bit. I am hopeful that the official support for library-projects-as-JARs will be available soonish.




回答2:


It means that (at the current time) you must distribute your entire project folder. Rather than just a jar file like you can for java libraries.

When someone wants to use your library they will import your project into eclipse, and then in project properties->android they will add your project as an android library.

A few common ways used to distribute a Library project are by using git, or zipping your project folder and making it available online.



来源:https://stackoverflow.com/questions/15255264/how-to-distribute-an-android-library

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