分类: 嵌入式
2012-04-05 15:15:04
使用第三方jar包
除了我以下介绍的方法,别的方法我基本上都试验过,均会出现编译或运行错误。以下方法经测试编译和运行都完全没问题。
步骤:
方法1:Eclipse下,
3、在libs目录上点右键,选Bulid path –> Use as source folder。
方法2,android源码环境下,
1,将out/target/common/obj/JAVA_LIBRARIES/powersave_intermediates下的classess.jar文件放在自己的工程目录下。out/target/product/ventana/system/framework目录下的jar包用以下方法经验证是不好使的,因为他已经打成dex文件了,在工程里引用其包是不行的;
2,修改android.mk文件,如下:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_STATIC_JAVA_LIBRARIES := libpowerjar libpowersave
LOCAL_PACKAGE_NAME := testPowerjar
LOCAL_CERTIFICATE := platform
include $(BUILD_PACKAGE)
##############################################
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libpowerjar:classes.jar libpowersave:testlily.jar
include $(BUILD_MULTI_PREBUILT)
# Use the folloing include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
解释:LOCAL_STATIC_JAVA_LIBRARIES :=libpowerjar和LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES :=libpowerjar:classes.jar其实libarity是个名字可以随便取,两个属性的值要一样就好了,但是后面那个冒号里面就一定要写你的jar包名,你的jar包一定放在工程的根目录就好了。我这里是使用两个jar包的例子。
3,源码目录下编译即可:# mmm package/app/testPowerjar,如果出错提示说找不到jar包所打的package,那么请#touchclasses.jar 即可.
生成jar包:
方法1:Eclipse下,
1. 创建java 或android project;
2. 工程属性java build path->Libraries中加入android.jar
3. package explorer中右键点击工程,export java->jar file.
方法2:Android源码环境下
1,修改Android.mk文件,
LOCAL_PATH:= $(call my-dir)
# the library
# ============================================================
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := powersave.javaLOCAL_MODULE := powersave
include $(BUILD_JAVA_LIBRARY)
# additionally, build unit tests in a separate .apk
include $(call all-makefiles-under,$(LOCAL_PATH))
2,编译 # mmm powersave(自己的模块)
其中,BUILD_JAVA_LIBRARY代表生成jar包,包的位置放在out/target/product/ventana/system/framework和out/target/common/obj/JAVA_LIBRARIES/powersave_intermediates(自己的模块)下,
参考: