在android中,编译的项目使用到第三方jar的导入方法 终极版!
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
解决的方法都是在网上找了,自己总结一下。谢谢各位在网上的分享。
在android中,编译的项目使用到第三方jar的导入方法 终极版!的更多相关文章
- MyEclipse中把java项目打包——含有第三方jar包【转】
也适用于eclipse导出jar. 在将项目打包为jar包时一直出现“ClassNotDefFound”错误,百度了很多解决办法都没有解决.最终找到一个很好的解决办法. 1.打包步骤 (1)右键单击j ...
- 在Eclipse中编译maven项目出的问题
在Eclipse中编译Maven项目,运行 jetty:run 指令的时候会出错,在 JRE选项卡中加入: -Dorg.mortbay.util.URI.charset=GBK-Xms512m -Xm ...
- 【转】Android中引入第三方Jar包的方法(java.lang.NoClassDefFoundError解决办法)
原文网址:http://www.blogjava.net/anchor110/articles/355699.html 1.在工程下新建lib文件夹,将需要的第三方包拷贝进来.2.将引用的第三方包,添 ...
- MyEclipse中android 项目如何解决第三方jar无法关联源码的问题( The JAR of this class file belongs to container 'Android Private Libraries' which does not allow modifications to source attachments on its entries.)
若我们要为第三方jar(android-support-v4.jar)关联源码通常的做法是 右键项目 单击菜单Properties 单击菜单 Java Build Path 单击 Libraries ...
- maven项目引入外部第三方jar包,引入、本地编译、第三方jar一起打到jar中、在linux机器中解决classnotfound(配置classpath),笔记整理。
文章目录 引用的第三方jar的目录结构(示例) 引入第三方jar进行dependency使项目内能import 本地编译 第三方jar一起打到jar中 在linux机器中解决classnotfound ...
- [Android]proguard重新编译和如何不混淆第三方jar包
转载自:http://glblong.blog.51cto.com/3058613/1536516 一.ant安装.环境变量配置及验证 (一)安装ant 到官方主页http://ant.apache. ...
- Android项目:proguard混淆第三方jar.
1.Gson混淆 ## ---------------------------------- ## ########## Gson混淆 ########## ## ------------- ...
- Android : 关于HTTPS、TLS/SSL认证以及客户端证书导入方法
一.HTTPS 简介 HTTPS 全称 HTTP over TLS/SSL(TLS就是SSL的新版本3.1).TLS/SSL是在传输层上层的协议,应用层的下层,作为一个安全层而存在,翻译过来一般叫做传 ...
- Android Studio编译开源项目(含NDK开发)常见报错
1.未设置NDK的路径 Error:Execution failed for task ':library:ndkBuild'. > A problem occurred starting pr ...
随机推荐
- NOIP 2017 时间复杂度 (模拟)
题目大意:略 傻了吧唧的我wa了好几次 我的模拟功底真的不咋地 linux下用gets会报错,我用的fgets #include <string> #include "stdio ...
- 微信支付报ip错,怀疑是因为不能正确获取$_Server[addr])ip导致的
报如下错误,应该是本地测试环境不能正确获取客户ip导致的错误 果然 放到服务器上在测试就好了
- Linux学习总结(16)——CentOS 下 Nginx + Tomcat 配置负载均衡
最近在读埃隆·马斯克传记,他说「我认为现在有非常多的聪明人都在致力于互联网」. 仔细一想,好像真的是这样的. 我问了自己一个问题:如果你不敲代码了,你能做什么? 答案令人极其恐怖.吓得我赶紧又去写了一 ...
- POJ 3749
第一道简单密码学的题,太水了,本不打算做,第一道,还是纪念一下. #include <iostream> #include <cstdio> #include <cstr ...
- [Puppeteer] Get a Page's Load Time with Puppeteer (window.profermence.timing)
In this lesson we are going to use Google's Puppeteer to gather metrics about a page's load time. We ...
- Centos yum 安装lamp PHP5.4版本号
centos 6.5 1.yum安装和源码编译在使用的时候没啥差别.可是安装的过程就大相径庭了,yum仅仅须要3个命令就能够完毕,源码须要13个包,还得加压编译.步骤非常麻烦,并且当做有时候会出错,源 ...
- _00017 Kafka的体系结构介绍以及Kafka入门案例(0基础案例+Java API的使用)
博文作者:妳那伊抹微笑 itdog8 地址链接 : http://www.itdog8.com(个人链接) 博客地址:http://blog.csdn.net/u012185296 博文标题:_000 ...
- ios修改了coredata数据结构后,更新安装会闪退
如果iOS App 使用到CoreData,并且在上一个版本上有数据库更新(新增表.字段等操作),那在覆盖安装程序时就要进行CoreData数据库的迁移,具体操作如下: 1.选中你的mydata.xc ...
- systemd服务管理--systemctl常用命令
转自 :https://m635674608.iteye.com/blog/2359480 1. #systemctl enable crond.service //让某个服务开机启动(.servic ...
- Mysql实战45讲 04讲深入浅出索引(上)读书笔记 极客时间
极客时间 Mysql实战45讲 04讲深入浅出索引 极客时间(上)读书笔记 笔记体悟 1.索引的作用:提高数据查询效率2.常见索引模型:哈希表.有序数组.搜索树3.哈希表:键 - 值(key - v ...