如何创建罐为Android库项目 [英] How to create jar for Android Library Project

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

问题描述

我要创造,我要出口到客户在一个jar文件库。请问有什么办法可以在其中创建与资源罐子?

I have to create a library that I am going to export to the client in a jar file. Is there any way to create a jar with the resources in it?

在谷歌的AdMob有这样一个罐子,其中包括资源文件,如R $ layout.class在里面。 本页面介绍了一些方法来做到这一点,但我不能够正确理解我怎么到库项目导入到使用上述方法的应用程序

The Google adMob have such a jar, which includes resource file such as R$layout.class in it. This page describes some way to do that but I am not able to understand exactly how am I supposed to import the library project to an application using the method above.

推荐答案

这是最接近的,你可以得到:

This is the closest that you can get:

步骤#1:创建一个普通的Andr​​oid库项目,并得到它的工作

Step #1: Create a regular Android library project, and get it working.

步骤2:将复制的Andr​​oid库项目到另一个目录

Step #2: Copy that Android library project into another directory.

第三步:建立从原生Android库项目已编译的Java类的JAR,并把该JAR在你做副本中的库/ 目录第2步。你应该可以手动对这个JAR运行ProGuard的,虽然我还没有尝试过。

Step #3: Create a JAR from the compiled Java classes from the original Android library project, and put that JAR in the libs/ directory of the copy you made in Step #2. You should be able to run ProGuard on this JAR manually, though I haven't tried that.

第四步:删除所有的复制库项目的的src / 目录中,留下空的src / 目录。

Step #4: Remove everything inside the src/ directory of the copied library project, leaving behind and empty src/ directory.

步骤#5:ZIP或以其他方式分发复制的Andr​​oid库项目

Step #5: ZIP up or otherwise distribute the copied Android library project.

这会给你一个Android库项目,如播放业务之一,那里的资源可用,但源$ C ​​$ c不是。

This will give you an Android library project like the Play Services one, where the resources are available, but the source code is not.

更新:一个更好的办法现在是打包库项目作为一个AAR,这是创建从你的编译code以及所需的资源可重复使用的神器Android的原生方式。在present时间(2014年7月)摇篮为Android,Android的工作室,和 Android的Maven的插件可以创建和使用AARS。

UPDATE: An even better approach nowadays is to package your library project as an AAR, which is Android's native way of creating a reusable artifact from your compiled code plus required resources. At the present time (July 2014), Gradle for Android, Android Studio, and the android-maven-plugin can create and consume AARs.

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

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