如何将 Android 库项目转换为外部 JAR? [英] How to Convert an Android Library Project to an External JAR?

查看:21
本文介绍了如何将 Android 库项目转换为外部 JAR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常适合我的 Android 库项目,但现在我有兴趣将其转换"为外部 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?如果不是,有什么限制或限制?

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

推荐答案

是否可以将任何 Android 库项目转换为外部 JAR?

Can any Android library project be converted to an external JAR?

现在不行.

如果没有,有什么限制或限制?

If not, what are the restrictions or limitations?

如果您的库是纯 Java 代码,没有资源,您可以使用 .class 文件创建 JAR,就像使用常规 Java 一样.

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.

如果您的库使用资源,您仍然可以像上面一样创建 JAR.但是,您需要通过反射或 getIdentifier() 查找 R 值(例如,R.layout.main),并且您的资源不会打包在 JAR 中,而是必须单独分发.

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.

在未来,构建工具应该支持从库项目中创建可分发的 JAR 文件,并带有资源.当前的构建工具确实会创建 JAR,但它们并不是为分布式而设计的,而是目前的内部构建工件.

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.

这篇关于如何将 Android 库项目转换为外部 JAR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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