建库项目 [英] Build library project

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

问题描述

所有。 我创建了一个Android库项目,它是完美的作品,当我从主项目引用它。但是,当我建库项目除了它不包含R.​​java和资源。有没有办法建立一个库项目的资源和R.java?

all. I've created an android library project and it's works perfectly when i reference it from main project. But when i build the library project apart it doesn't contains R.java and resources. Is there way to build a library project with resources and R.java?

推荐答案

这是不可能的了。

现在,我们可以通过以下步骤创建一个二进制只有库项目:

Now we can create a binary-only library project via the following steps:

  1. 创建一个Android库项目,与源$ C ​​$ c和这样的 - 这是你的主项目,从中你将创建一个版本 库项目分布
  2. 编译Java源代码(例如,蚂蚁编译),并把它变成一个JAR文件
  3. 创建一个分发的Andr​​oid库项目,用相同的 资源作为主库项目,但没有源$ C ​​$ C
  4. 把JAR文件中分发的Andr​​oid库项目的库/ 目录 由此产生的分配的Andr​​oid库项目将拥有一切一 主体工程需要,只是没有源$ C ​​$ C。
  1. Create an Android library project, with your source code and such – this is your master project, from which you will create a version of the library project for distribution
  2. Compile the Java source (e.g., ant compile) and turn it into a JAR file
  3. Create a distribution Android library project, with the same resources as the master library project, but no source code
  4. Put the JAR file in the distribution Android library project's libs/ directory The resulting distribution Android library project will have everything a main project will need, just without the source code.

目前在这个解决方案的一些限制:

There is some restrictions in this solution:

  1. 我们还是要出货的资源。
  2. 我们要改写我们的code,以避免使用R.值,因为它们 将是错误的。我们将使用查找所有的资源标识 getResources()。则getIdentifier()和/或反射。
  1. We still have to ship the resources.
  2. We have to rewrite our code to avoid using R. values, as they will be wrong. We will have to look up all resource IDs using getResources().getIdentifier() and/or reflection.

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

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