创建针对Android库分发的JAR [英] Create a JAR for Android Library Distribution

查看:117
本文介绍了创建针对Android库分发的JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个机器人库,并希望导出我可以分发供其他人在他们的应用程序使用的JAR文件。我不希望,因为它包含了发布到我的Web服务器的详细信息分发源$ C ​​$ C。

我已经使用在bin目录下创建的JAR文件和jar文件复制到我的项目,我的项目中引用它,并勾选导出按钮尝试。

当我尝试运行我的项目引用,我已经复制的图书馆,我的应用程序抛出与的NoClassDefFoundError 例外。我做了一些谷歌搜索和一切我发现意味着你必须提供源$ C ​​$ c和让用户导入到他们的IDE,然后引用该项目到他们的应用程序,我不想做的事。作为其他公司可以包括库提供的JAR文件必须有可能。

感谢您的帮助。


解决方案

  

我不希望,因为它包含了发布到我的Web服务器的详细信息分发源$ C ​​$ C。


请记住,任何人谁想要可以得到的数据拿出来。


  

作为其他公司可以包括库提供的JAR文件必须有可能


据我所知,这个配方仍然有效:


  1. 创建一个Android库项目,用你的源$ C ​​$ C,资源,这样,得到它的工作


  2. 编译Java源代码(例如,通过Ant),并把它变成一个JAR文件


  3. 创建您的原生Android库项目作为一个分布的Andr​​oid库项目的副本


  4. 将步骤#2编译JAR,并把它放在从步骤#配电库项目/的库3。


  5. 删除的src / 分布库项目的一切(但保留现在空的src / 目录里有)


  6. 分发配送库项目(例如,ZIP它)


这有效地给你什么你使用Play服务SDK看到 - 库项目不包含源$ C ​​$ C,而是在JAR 库/ ,沿同的资源和诸如

我将reconfiming这个食谱明天会努力记住,如果我发现它需要调整的工具的当前作物来更新这个答案。

和新的基于摇篮构建系统支持AAR包分发库和这样的,虽然我还没有与此发挥呢。


更新

这个食谱的作品,只要库项目本身没有对另一个JAR或库项目的依赖。在这种情况下,事情似乎在构建过程中得到搞砸了 - 一切都可以编译,但是从依赖类引用不能在运行时解析

I am working on an android library, and wish to export a JAR file that I can distribute for others to use in their apps. I don't want to distribute the source code as it contains details on posting to my web server.

I have tried using the JAR file that is created in the bin directory and copying the jar file to my project and referencing it within my project and ticking the export button.

When I try and run my project referencing the library that I've copied, my app throws an exception with NoClassDefFoundError. I've done some Googling and everything I have found suggests you have to provide the source code and let the user import into their IDE and then reference that project into their app which I don't want to do. It must be possible as other companies provide JAR files for libraries that can be included.

Thanks for your help.

解决方案

I don't want to distribute the source code as it contains details on posting to my web server.

Bear in mind that anyone who wants to can get that data out of the JAR.

It must be possible as other companies provide JAR files for libraries that can be included.

AFAIK, this recipe still works:

  1. Create an Android library project, with your source code, resources, and such, and get it working

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

  3. Create a copy of your original Android library project to serve as a distribution Android library project

  4. Place the compiled JAR from step #2 and put it in libs/ of the distribution library project from step #3.

  5. Delete everything in src/ of the distribution library project (but leave the now-empty src/ directory there)

  6. Distribute the distribution library project (e.g., ZIP it up)

This effectively gives you what you see with the Play Services SDK -- a library project with no source code, but instead a JAR in libs/, along with the resources and such.

I will be reconfiming this recipe tomorrow and will try to remember to update this answer if I find that it needs adjusting for the current crop of tools.

And the new Gradle-based build system supports the AAR package for distributing libraries and such, though I have not played with this yet.


UPDATE

This recipe works, so long as the library project does not itself have dependencies upon another JAR or library project. In those cases, things seem to get messed up in the build process -- everything can compile, but class references from the dependencies cannot be resolved at runtime.

这篇关于创建针对Android库分发的JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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