Skip to content

Commit

Permalink
fixed #101
Browse files Browse the repository at this point in the history
  • Loading branch information
hongyangAndroid committed Mar 10, 2016
1 parent 387b79f commit 5711f2d
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 9 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
或者

```
compile 'com.zhy:okhttputils:2.3.5'
compile 'com.zhy:okhttputils:2.3.6'
```

* Eclipse

下载最新jar:[okhttputils-2_3_5.jar](okhttputils-2_3_5.jar?raw=true)
下载最新jar:[okhttputils-2_3_6.jar](okhttputils-2_3_6.jar?raw=true)

注:需要同时导入okhttp和okio的jar,下载见:[https://github.com/square/okhttp](https://github.com/square/okhttp).

Expand Down Expand Up @@ -402,7 +402,25 @@ protected void onDestroy()
```
比如,当前Activity页面所有的请求以Activity对象作为tag,可以在onDestory里面统一取消。

## 混淆

```
#okhttputils
-dontwarn com.zhy.http.**
-keep class com.zhy.http.**{*;}
-keep interface com.zhy.http.**{*;}
#okhttp
-dontwarn okhttp3.**
-keep class okhttp3.**{*;}
-keep interface okhttp3.**{*;}
#okio
-dontwarn okio.**
-keep class okio.**{*;}
-keep interface okio.**{*;}
```



Expand Down
Binary file renamed okhttputils-2_3_5.jar → okhttputils-2_3_6.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions okhttputils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = "2.3.5"
version = "2.3.6"

android {
compileSdkVersion 23
Expand Down Expand Up @@ -123,7 +123,7 @@ task makeJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('build/outputs/')
include('classes.jar')
rename ('classes.jar', 'okhttputils-2_3_5.jar')
rename ('classes.jar', 'okhttputils-2_3_6.jar')
}

makeJar.dependsOn(clearJar, build)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public OkHttpUtils(OkHttpClient okHttpClient)
OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder();
//cookie enabled
okHttpClientBuilder.cookieJar(new SimpleCookieJar());
mDelivery = new Handler(Looper.getMainLooper());
okHttpClientBuilder.hostnameVerifier(new HostnameVerifier()
{
@Override
Expand All @@ -55,12 +54,19 @@ public boolean verify(String hostname, SSLSession session)
return true;
}
});

mOkHttpClient = okHttpClientBuilder.build();
} else
{
mOkHttpClient = okHttpClient;
}

init();
}

private void init()
{
mDelivery = new Handler(Looper.getMainLooper());
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.zhy.http.okhttp.callback;

import okhttp3.Response;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.utils.L;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import okhttp3.Response;

/**
* Created by zhy on 15/12/15.
*/
Expand Down Expand Up @@ -51,8 +51,6 @@ public File saveFile(Response response) throws IOException
final long total = response.body().contentLength();
long sum = 0;

L.e(total + "");

File dir = new File(destFileDir);
if (!dir.exists())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public synchronized List<Cookie> loadForRequest(HttpUrl url)
if (cookie.matches(url))
{
// Log.e("===loadForRequest", cookie.name() + " , " + cookie.value());
// Log.e("===loadForRequest", cookie.expiresAt() + " . " + System.currentTimeMillis());
result.add(cookie);
}
}
Expand Down
1 change: 1 addition & 0 deletions sample-okhttp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}

}
}

Expand Down
107 changes: 107 additions & 0 deletions sample-okhttp/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,110 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
#shrink,测试后发现会将一些无效代码给移除,即没有被显示调用的代码,该选项 表示 不启用 shrink。
-dontshrink
#指定重新打包,所有包重命名,这个选项会进一步模糊包名,将包里的类混淆成n个再重新打包到一个个的package中
-flattenpackagehierarchy
#优化时允许访问并修改有修饰符的类和类的成员
-allowaccessmodification
#混淆前后的映射
-printmapping map.txt
#不跳过(混淆) jars中的 非public classes 默认选项
-dontskipnonpubliclibraryclassmembers
#忽略警告
-ignorewarnings
#指定代码的压缩级别
-optimizationpasses 5
#不使用大小写混合类名
-dontusemixedcaseclassnames
#不去忽略非公共的库类
-dontskipnonpubliclibraryclasses
#不启用优化 不优化输入的类文件
-dontoptimize
#不预校验
-dontpreverify
#混淆时是否记录日志
-verbose
#混淆时所采用的算法
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
#保护注解
-renamesourcefileattribute SourceFile
#保持源文件和行号的信息,用于混淆后定位错误位置
-keepattributes SourceFile,LineNumberTable
-keepattributes SourceFile,LineNumberTable
#保持含有Annotation字符串的 attributes
-keepattributes *Annotation*
-keepattributes Signature
-keepattributes Exceptions,InnerClasses

-dontwarn org.apache.**
-dontwarn android.support.**

#基础配置
# 保持哪些类不被混淆
# 系统组件
-keep public class * extends android.app.Fragment
-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
#如果有引用v4包可以添加下面这行
-keep public class * extends android.support.v4.app.Fragment
#自定义View
-keep public class * extends android.view.View
# V4,V7
-keep class android.support.v4.**{ *; }
-keep class android.support.v7.**{ *; }
-keep class android.webkit.**{*;}
-keep interface android.support.v4.app.** { *; }
#保持 本化方法及其类声明
-keepclasseswithmembers class * {
native <methods>;
}
#保持view的子类成员: getter setter
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
#保持Activity的子类成员:参数为一个View类型的方法 如setContentView(View v)
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
#保持枚举类的成员:values方法和valueOf (每个enum 类都默认有这两个方法)
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
#保持Parcelable的实现类和它的成员:类型为android.os.Parcelable$Creator 名字任意的 属性
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
#保持 任意包名.R类的类成员属性。 即保护R文件中的属性名不变
-keepclassmembers class **.R$* {
public static <fields>;
}

#MPermission
-dontwarn com.zhy.m.**
-keep class com.zhy.m.** {*;}
-keep interface com.zhy.m.** { *; }
-keep class **$$PermissionProxy { *; }

#okio
-dontwarn okio.**
-keep class okio.**{*;}
-keep interface okio.**{*;}

#okhttputils
-dontwarn com.zhy.http.**
-keep class com.zhy.http.**{*;}
-keep interface com.zhy.http.**{*;}

#okhttp
-dontwarn okhttp3.**
-keep class okhttp3.**{*;}
-keep interface okhttp3.**{*;}

0 comments on commit 5711f2d

Please sign in to comment.