文章正文
Android开发遇到的破事(一)
在前几天做了一个demo,昨天升级了一下SDK,突然一下子就不能运行了,报了两个错。
1、报了android.os.NetworkOnMainThreadException的异常,这个好说,百度一下,easy。
原因:原来是在4.0之后在主线程里面执行Http请求都会报这个错
解决办法:在启动的activity的onCreate函数添加以下代码:
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
这样子不通用,最好的办法还是使用子线程去做网络的请求。
2、在编译的阶段,得到了下面的error:
The library 'cbl_collator_so-1.0.0.jar' contains native libraries that will not run on the device. Additionally some of those libraries will interfer with the installation of the application because of their location in lib/ lib/ is reserved for NDK libraries. The following libraries were found: - lib/armeabi-v7a/libcom_couchbase_touchdb_RevCollator.so ...
先说明一下背景,这个demo是测试一下couchbase mobile数据库的,先从官网上下了所有的jar包,在原来的版本中正常运行,升级了之后,在bin目录中多了一个dexedLibs目录,这个目录据说是为了加快编译速度的。说了一堆的废话,没有说原因。报这个error的原因就是升级了SDK后,这个jar不能在安装的时候,将so释放到apk所在的lib目录中,这样就导致引用这些so库的类不能运行,其实,报了这个错之后apk是可以生成的,但是不能安装。
解决:将jar改名zip,将里面的内容解压出来,放到libs目录下,如果没有新建一个。将cbl_collator_so-1.0.0,jar从工程中去掉。OK。
Dec. 9, 2015, 9:54 p.m. 作者:zachary 分类:Android 阅读(1846) 评论(0)
评论列表:
评论: