1,在android系统环境中编译自己的项目时,往往会用到第三方jar包。这些jar包在eclipse中添加编译,一路畅通,因为eclipse已经帮助你配置好了。但是当把这个项目拷贝到系统环境中编译时,jar包就会不管用。下面是自己遇到的问题,通过查找网上的资料,遇到各种问题,最后终于解决。通过博客总结一下,给大家分享。
条件:例如:先在eclipse中开发的应用,用到support-v4包和第三方pinyin4j-2.5.0.jar。
移植到系统项目中,编译不通过。以系统的music应用为例。
1,首先之是加入Android.mk文件
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src) \
src/com/android/music/IMediaPlaybackService.aidl
LOCAL_PACKAGE_NAME := Music
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
include $(BUILD_PACKAGE)
编译会找不到引用的包中相应的类和方法。
2,然后在声明包,在.mk中添加
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
#声明包名
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4 pinyin4j-2.5.0
LOCAL_SRC_FILES := $(call all-java-files-under, src) \
src/com/android/music/aidl/IMediaService.aidl
LOCAL_PACKAGE_NAME := Music
include $(BUILD_PACKAGE)
include $(CLEAR_VARS)
#指明包的位置
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := pinyin4j-2.5.0:lib/pinyin4j-2.5.0.jar
include $(BUILD_MULTI_PREBUILT)
3,这时编译有可能还会报错。(...can't find superclass or interface...)
Warning: demo.Pinyin4jAppletDemo$1: can't find superclass or interface java.awt.event.WindowAdapter
Warning: demo.Pinyin4jAppletDemo$3: can't find superclass or interface java.awt.event.ActionListener
Warning: demo.Pinyin4jAppletDemo$2: can't find superclass or interface java.awt.event.ActionListener
Warning: demo.Pinyin4jAppletDemo: can't find superclass or interface javax.swing.JApplet
Warning: demo.Pinyin4jAppletDemo$1: can't find referenced class java.awt.event.WindowAdapter
Warning: demo.Pinyin4jAppletDemo$1: can't find referenced method 'void stop()' in class demo.Pinyin4jAppletDemo
Warning: demo.Pinyin4jAppletDemo$1: can't find referenced method 'void destroy()' in class demo.Pinyin4jAppletDemo
Warning: demo.Pinyin4jAppletDemo$1: can't find referenced class java.awt.event.WindowAdapter
Warning: demo.Pinyin4jAppletDemo$1: can't find referenced class java.awt.event.WindowEvent
Warning: demo.Pinyin4jAppletDemo$3: can't find referenced class javax.swing.JComboBox
Warning: demo.Pinyin4jAppletDemo$3: can't find referenced class javax.swing.JComboBox
这好像的混淆编译造成的错误,然后在应用的根目录下建立proguard.cfg这个文件,在里面输入:
-dontwarn demo.**
-keep class demo.** { *;}
查看编译报的错误,有几个包出错,就在里面加几个这样的声明。这里是有demo.下的java报错,只加这个就行。然后在Android.mk中添加此文件的标识。
LOCAL_PROGUARD_FLAG_FILES := proguard.cfg
然后在编译,应该就可以通过。
大功告成。。。
2,然后后来又用到另一个jar包,出现了新问题:以下是出现的warring:
Warning: org.opencv.android.CameraBridgeViewBase: can't find referenced class org.opencv.R$styleable
Warning: org.opencv.android.CameraBridgeViewBase: can't find referenced class org.opencv.R$styleable
Warning: org.opencv.android.CameraBridgeViewBase: can't find referenced class org.opencv.R
×××××
Warning: there were 3 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars'),
or perhaps the '-dontskipnonpubliclibraryclasses' option.
使用上面的方法就不管用。但是在proguard.cfg文件中添加一句这个就可以忽略warring。
-ignorewarnings
解决办法都是在网上找了,自己总结一下。谢谢各位在网上的分享。