android { useLibrary 'org.apache.http.legacy' }
注意放置的位置:是在android {}中
可以參考:
https://developer.Android.com/preview/behavior-changes.html
最新的android-async-http的已經(jīng)按上面的方法,更新了。
另外:在eclipse中,加入org.apache.http.legacy.jar后,把a(bǔ)ndroid sdk版本改為低于6.0也可以正常使用
附加:
u013004268:加了上面的jar,混淆出現(xiàn)問(wèn)題
解決方法:
對(duì)這個(gè)jar,不做混淆處理
下面是混淆配置(eclipse上面測(cè)試通過(guò))
混淆配置: #不混淆android-async-http(這里的與你用的httpClient框架決定)
-keep class com.loopj.android.http.**{*;}
#不混淆org.apache.http.legacy.jar
-dontwarn android.net.compatibility.**
-dontwarn android.net.http.**
-dontwarn com.android.internal.http.multipart.**
-dontwarn org.apache.commons.**
-dontwarn org.apache.http.**
-keep class android.net.compatibility.**{*;}
-keep class android.net.http.**{*;}
-keep class com.android.internal.http.multipart.**{*;}
-keep class org.apache.commons.**{*;}
-keep class org.apache.http.**{*;} 最后是完整的混淆配置文件的內(nèi)容: - -ignorewarnings
-
- # 指定代碼的壓縮級(jí)別
- -optimizationpasses 5
- # 不使用大小寫(xiě)混合
- -dontusemixedcaseclassnames
- # 混淆第三方j(luò)ar
- -dontskipnonpubliclibraryclasses
- # 混淆時(shí)不做預(yù)校驗(yàn)
- -dontpreverify
- # 混淆時(shí)記錄日志
- -verbose
- # 混淆時(shí)所采用的算法
- -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-
- # 保持哪些類不被混淆:四大組件,應(yīng)用類,配置類等等
- -keep public class * extends android.app.Activity
- -keep public class * extends android.app.Application
- -keep public class * extends android.app.Service
- -keep public class * extends android.content.BroadcastReceiver
- -keep public class * extends android.content.ContentProvider
- -keep public class * extends android.app.backup.BackupAgentHelper
- -keep public class * extends android.preference.Preference
- -keep public class com.android.vending.licensing.ILicensingService
-
- # 保持 native 方法不被混淆
- -keepclasseswithmembernames class * {
- native <methods>;
- }
-
- # 保持自定義控件類不被混淆
- -keepclasseswithmembers class * {
- public <init>(android.content.Context, android.util.AttributeSet);
- }
-
- # 保持自定義控件類不被混淆
- -keepclasseswithmembers class * {
- public <init>(android.content.Context, android.util.AttributeSet, int);
- }
-
- # 保持自定義控件類不被混淆
- -keepclassmembers class * extends android.app.Activity {
- public void *(android.view.View);
- }
-
- # 保持枚舉 enum 類不被混淆
- -keepclassmembers enum * {
- public static **[] values();
- public static ** valueOf(java.lang.String);
- }
-
- # 保持 Parcelable 不被混淆
- -keep class * implements android.os.Parcelable {
- public static final android.os.Parcelable$Creator *;
- }
- # 這個(gè)主要是在layout中寫(xiě)的onclick方法android:onclick="onClick",不進(jìn)行混淆
- -keepclassmembers class * extends android.app.Activity {
- public void *(android.view.View);
- }
-
- #保持注解
- -keepattributes *Annotation*
-
- #不混淆android-async-http
- -keep class com.loopj.android.http.**{*;}
-
- #不混淆org.apache.http.legacy.jar
- -dontwarn android.net.compatibility.**
- -dontwarn android.net.http.**
- -dontwarn com.android.internal.http.multipart.**
- -dontwarn org.apache.commons.**
- -dontwarn org.apache.http.**
- -keep class android.net.compatibility.**{*;}
- -keep class android.net.http.**{*;}
- -keep class com.android.internal.http.multipart.**{*;}
- -keep class org.apache.commons.**{*;}
- -keep class org.apache.http.**{*;}
-
-
-
|