android 打包第三方jar包

android项目开发时会用到第三方提供的jar包,通常情况下按照eclipse导入jar包的方法(选择项目,右键点击Build Path,Build Path–>Add Libraries–>User Library–>Next–>User Libraries–>New–>Add JARs,选择第三方的jar包),就可以将jar包导入到项目。

根据这样的打包方式时,eclipse导入jar包后,eclipse编译器也能识别,即项目不会因为缺少jar包而报错,但是运行android程序的时候却没有找到包而报错了。APK文件也很小,也就是jar包并没有打包到APK文件中。

在android项目中找到.classpath文件并打开,文件代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
    <classpathentry kind="lib" path="E:/Code/android/Lib/MapApi.jar"/>
    <classpathentry kind="lib" path="E:/Code/android/Lib/xpp3_min-1.1.4c.jar"/>
    <classpathentry kind="lib" path="E:/Code/android/Lib/xstream-for-android-1.0.0.jar"/>
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
    <classpathentry kind="output" path="bin/classes"/>
</classpath>

发现如下一行包含有exported

 <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>

如是我想,是不是lib中也要加呢,修改为如下:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
    <classpathentry exported="true" kind="lib" path="E:/Code/android/Lib/MapApi.jar"/>
    <classpathentry exported="true" kind="lib" path="E:/Code/android/Lib/xpp3_min-1.1.4c.jar"/>
    <classpathentry exported="true" kind="lib" path="E:/Code/android/Lib/xstream-for-android-1.0.0.jar"/>
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
    <classpathentry kind="output" path="bin/classes"/>
</classpath>

在打包,文件变大了,呵呵,应该文件打包进去了。

经过测试,确实成功了,只是下一步想知道怎么在eclipse中设置。

posted @ 2012-09-26 10:40  lexloo  阅读(322)  评论(0编辑  收藏  举报
ccc