android http 改用了okhttp,Android mk编译OkHttp3

使用OkHttp,放到framework层编译,编译错误:

Warning: okio.DeflaterSink: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

Warning: okio.Okio: can't find referenced class java.nio.file.Files

Warning: okio.Okio: can't find referenced class java.nio.file.Files

Warning: okio.Okio: can't find referenced class java.nio.file.Files

Warning: okio.Okio: can't find referenced class java.nio.file.Path

Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption

Warning: okio.Okio: can't find referenced class java.nio.file.Path

Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption

Warning: okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

Warning: okio.Okio: can't find referenced class java.nio.file.Path

Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption

Warning: okio.Okio: can't find referenced class java.nio.file.Path

Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption

Warning: okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

Warning: there were 14 unresolved references to classes or interfaces.

You may need to add missing library jars or update their versions.

If your code works fine without the missing classes, you can suppress

the warnings with '-dontwarn' options.

(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)

Error: Please correct the above warnings first.

编译环境:

Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 3.16.0-40-generic x86_64)

miyuehu@ubuntu:~$ java -version

java version “1.7.0_101”

OpenJDK Runtime Environment (IcedTea 2.6.6) (7u101-2.6.6-0ubuntu0.14.04.1)

OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)

github okhttp FAQs

擦,不用管。

关键提示信息:“the warnings with ‘-dontwarn’ options”

修改Android.mk

###使能proguard.cfg

LOCAL_PROGUARD_ENABLED := full

LOCAL_PROGUARD_FLAG_FILES := proguard.cfg

LOCAL_CERTIFICATE := platform

include $(BUILD_PACKAGE)

include $(CLEAR_VARS)

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := okhttp:libs/okhttp-3.5.0.jar

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += okio:libs/okio-1.11.0.jar

include $(BUILD_MULTI_PREBUILT)

修改proguard.cfg

-dontwarn okio.**

目录结构: . ├── AndroidManifest.xml ├── Android.mk ├── assets ├── libs │?? ├── okhttp-3.5.0.jar │?? └── okio-1.11.0.jar

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可能是你的代码中出现了一些错误,或者是缺少一些必要的依赖库。以下是一些可能导致该错误的常见原因和解决方案: 1. 没有添加Okhttp的依赖库:在你的build.gradle文件中添加以下依赖: ``` implementation 'com.squareup.okhttp3:okhttp:3.14.9' ``` 2. 没有添加网络权限:在你的AndroidManifest.xml文件中添加以下代码: ``` <uses-permission android:name="android.permission.INTERNET" /> ``` 3. 没有在主线程中执行网络操作:Okhttp默认是在后台线程中执行网络操作,如果你需要在主线程中执行网络操作,可以使用Okhttp的enqueue()方法,例如: ``` OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("http://www.example.com") .build(); client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { // 处理错误 } @Override public void onResponse(Call call, Response response) throws IOException { // 处理响应 } }); ``` 4. 没有在AndroidManifest.xml中添加android:usesCleartextTraffic属性:如果你的应用程序需要使用明文http请求,需要在AndroidManifest.xml中添加以下代码: ``` <application android:usesCleartextTraffic="true" ...> ... </application> ``` 5. 混淆规则错误:如果你使用了混淆,需要在你的proguard-rules.pro文件中添加以下代码: ``` -dontwarn okhttp3.** -keep class okhttp3.** { *; } -keep interface okhttp3.** { *; } ``` 希望以上解决方案能够帮助你解决问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值