简体   繁体   English

如何将Android库项目转换为外部JAR?

[英]How to Convert an Android Library Project to an External JAR?

I have an Android library project that has been working for me pretty well, but now I am interested in "converting" it to an external JAR. 我有一个Android库项目一直很适合我,但现在我有兴趣将它“转换”为外部JAR。

How do I do that? 我怎么做?

Can any Android library project be converted to an external JAR? 任何Android库项目都可以转换为外部JAR吗? If not, what are the restrictions or limitations? 如果没有,有什么限制或限制?

Can any Android library project be converted to an external JAR? 任何Android库项目都可以转换为外部JAR吗?

Not right now. 不是现在。

If not, what are the restrictions or limitations? 如果没有,有什么限制或限制?

If your library is purely Java code, with no resources, you can create a JAR out of the .class files, just as you would with regular Java. 如果您的库是纯Java代码,没有资源,您可以使用.class文件创建JAR,就像使用常规Java一样。

If your library uses resources, you can still create a JAR as above. 如果您的库使用资源,您仍然可以创建如上所述的JAR。 However, you will need to look up the R values (eg, R.layout.main ) via reflection or getIdentifier() , and your resources will not be packaged in the JAR but would have to be distributed separately. 但是,您需要通过reflection或getIdentifier()查找R值(例如, R.layout.main ),并且您的资源不会打包在JAR中,而是必须单独分发。

In the future, the build tools should support creating distributable JAR files out of library projects, complete with resources. 将来,构建工具应支持从库项目中创建可分发的JAR文件,并使用资源。 The current build tools do create JARs, but they are not designed to be distributed but are rather internal build artifacts at the moment. 当前的构建工具确实创建了JAR,但它们并非设计为分布式,而是目前的内部构建工件。

http://developer.android.com/guide/developing/projects/index.html#LibraryProjects claims that you can't export these to an external JAR. http://developer.android.com/guide/developing/projects/index.html#LibraryProjects声称您无法将这些导出到外部JAR。 Specific quote: 具体报价:

Similarly, you cannot export the library project to a self-contained JAR file, as you would do for a true library. 同样,您无法将库项目导出到自包含的JAR文件,就像对真正的库一样。 Instead, you must compile the library indirectly, by referencing the library in the dependent application and building that application. 相反,您必须通过引用依赖应用程序中的库并构建该应用程序来间接编译库。

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

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