4

我对 Android 开发很陌生,但我对 Java 和 Eclipse 有一些经验。我正在寻找创建可重用库(控件、助手、“标准”活动等)的方法,这些库可以在我自己的项目中使用,但也可以在不披露源代码的情况下分发给其他开发人员。

通常,我会将类文件打包到 JAR 文件中,任何其他开发人员都可以将其添加到类路径中并使用打包的类。

我怎样才能用 Android 项目做到这一点?我已经阅读了有关 Android 库项目的信息,但正如文档所述,它们不能打包到 JAR 中,而是会与引用库项目的项目一起编译。这意味着我还必须分发源代码。

我也读过这篇文章,它问了同样的问题,但没有提供令人满意的答案。

那么:有没有一种方法可以编译和打包一组类和其他文件(包括 XML 布局、资源和东西),并且只分发该包而无需任何源代码,以便它可以像 JAR 文件一样被“引用”和使用还有其他开发商吗?

4

3 回答 3

5

我已经阅读了有关 Android 库项目的信息,但正如文档所述,它们不能打包到 JAR 中,而是会与引用库项目的项目一起编译。这意味着我还必须分发源代码。

不对。它确实需要一些额外的打包工作,但您可以将代码编译为 JAR 并将 JAR 分发到库项目的libs/目录中。

那么:有没有一种方法可以编译和打包一组类和其他文件(包括 XML 布局、资源和东西),并且只分发该包而无需任何源代码,以便它可以像 JAR 文件一样被“引用”和使用还有其他开发商吗?

使用 Android 库项目。我在这里写了一些东西,描述了更多的打包选项,以及指向一些遵循其中描述的约定的“包裹”的指针。

于 2010-09-14T12:33:41.073 回答
0

Thanx for your solution. From what I understand, you still can not access the resources private to the library from within the libary code. So assume your library has a string resource named "my_lib_resource" under res/values in the library. You bundle this in the jar along with the source code. Can you access this resource from the library source code using something like:

int id = res.getIdentifier("com.example.mylib:string/my_lib_resource",null,null) 

assuming your library package name is com.example.mylib.

For me this does not work.

于 2011-02-08T22:22:02.150 回答
0

Brave new world of dependency management:

http://tools.android.com/recent/dealingwithdependenciesinandroidprojects

于 2013-09-17T04:40:47.750 回答