如何转换一个Android库项目到外部JAR?项目、Android、JAR

2023-09-12 07:29:31 作者:﹏ /巨☉蟒

我有一个Android库项目已为我工作pretty的很好,但我现在感兴趣的是转化到外部JAR。

我该怎么办呢?

可以在任何Android的库项目转换为外部JAR?如果不是,有什么要求和限制?

解决方案   

可以在任何Android的库项目转换为外部JAR?

现在不行。

  

如果不是,有什么要求和限制?

如果你的库是纯Java的code,没有资源,你可以创建一个JAR出的的.class 文件,就像你用普通的Java

eclipse android项目中android.jar关联源码后还是无法查看

如果您的库使用的资源,你仍然可以创建一个JAR如上。但是,你需要查找研究值( R.layout.main 如)通过反射或则getIdentifier(),和你的资源不会被打包在JAR但必须另行分配。

在未来,构建工具应该支持创建分发的JAR文件出库项目,完成资源。目前构建工具确实创造了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.

How do I do that?

Can any Android library project be converted to an external JAR? If not, what are the restrictions or limitations?

解决方案

Can any Android library project be converted to an external 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.

If your library uses resources, you can still create a JAR as above. However, you will need to look up the R values (e.g., R.layout.main) via reflection or getIdentifier(), and your resources will not be packaged in the JAR but would have to be distributed separately.

In the future, the build tools should support creating distributable JAR files out of library projects, complete with resources. The current build tools do create JARs, but they are not designed to be distributed but are rather internal build artifacts at the moment.