Skip to content

Commit

Permalink
更换脚本名,解决cdn更新不及时问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hss01248 committed May 21, 2021
1 parent 58d5110 commit 6596fcb
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
apply from:'remote2.gradle'
apply from:'remote2_0_0.gradle'
repositories {
google()
jcenter()
Expand Down
30 changes: 23 additions & 7 deletions flipper/src/main/java/com/hss01248/flipper/OkhttpAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,24 @@ public Object weaveJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable {
String className = methodSignature.getDeclaringType().getSimpleName();
String methodName = methodSignature.getName();
//String funName = methodSignature.getMethod().getAnnotation(TimeSpend.class).value();
Log.w(TAG,"method begin:"+methodName );
Log.v(TAG,"method begin:"+methodName );
//统计时间
long begin = System.currentTimeMillis();
Object result = null;
try {

if(joinPoint.getThis() instanceof OkHttpClient.Builder){
OkHttpClient.Builder builder = (OkHttpClient.Builder) joinPoint.getThis();
if(hooks.size() > 0){
for (int i = 0; i < hooks.size(); i++) {
hooks.get(i).beforeBuild(builder);
if(!isRN()){
if(joinPoint.getThis() instanceof OkHttpClient.Builder){
OkHttpClient.Builder builder = (OkHttpClient.Builder) joinPoint.getThis();
if(hooks.size() > 0){
for (int i = 0; i < hooks.size(); i++) {
hooks.get(i).beforeBuild(builder);
}
}
}
}else {
Log.v(TAG,"is fucking RN dev socket connector!!! ignore ");
}

result = joinPoint.proceed();
}catch (Throwable throwable){
throwable.printStackTrace();
Expand All @@ -60,6 +64,18 @@ public Object weaveJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable {
return result;
}

private boolean isRN() {
Exception exception = new Exception();
Log.e(TAG,"clientBuilder.build() call stacks",exception);
StackTraceElement[] stackTraces = exception.getStackTrace();
for (StackTraceElement stackTrace : stackTraces) {
if(stackTrace.getClassName().contains("com.facebook.react")){
return true;
}
}
return false;
}

public interface OkhttpHook{
void beforeBuild(OkHttpClient.Builder builder);
}
Expand Down
86 changes: 86 additions & 0 deletions remote2_0_0.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
rootProject.buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10'
}
}


def isRelease(){
for (String s : gradle.startParameter.taskNames) {
if (s.contains("ultiChannel") | s.contains("elease")) {
return true
}
}
return false
}

def hasApplyAspectjx(Project project0){
return project0.plugins.findPlugin("com.hujiang.android-aspectjx") != null || project0.plugins.findPlugin("android-aspectjx") != null
}


gradle.addProjectEvaluationListener(new ProjectEvaluationListener() {
@Override
void beforeEvaluate(Project project) {
println("---->beforeEvaluate:"+project)

}

@Override
void afterEvaluate(Project project, ProjectState projectState) {
println("---->afterEvaluate:"+project)
if(project.plugins.findPlugin("com.android.application") != null){
project.repositories {
maven { url 'https://jitpack.io' }
mavenCentral()
}

project.dependencies {
debugImplementation "com.github.hss01248.flipperUtil:flipper:1.0.4"
releaseImplementation "com.github.hss01248.flipperUtil:flipper-no-op:1.0.4"
}

if (!isRelease() && !hasApplyAspectjx(project)){
println("apply plugin: 'com.hujiang.android-aspectjx' by hss01248/flipperUtil, add flipper networkinterceptor to okhttpclient automatically")
project.apply plugin: 'com.hujiang.android-aspectjx'
//为加快编译速度,需要自己将扫描的包路径添加到include里. 性能差距: 4min vs 4s
project.aspectjx {
//排除所有package路径中包含`android.support`的class文件及库(jar文件):Invalid byte tag in constant pool
exclude 'com.google', 'com.taobao', 'com.alibaba', 'module-info', 'com.squareup.haha', 'versions.9', 'com.tencent',
'androidx',
//'com.squareup',
'com.alipay',
'org.apache',
'com.alipay',
'cn.jiguang',
//'com.github',
'com.meizu',
'com.huawei',
'com.qiyukf',
'com.sina',
'io.reactivex',
'de.greenrobot.event',
'com.netease.neliveplayer',
'com.umeng',
'im.yixin',
'com.commonsware',
'io.fabric',
'rx.android',
'com.android'

}
}else {
println("not apply aspectjx ,not add flipper networkinterceptor to okhttpclient automatically," +
"because isRelease or hasApplyAspectjx before : isRelease:"+isRelease()+",hasApplyAspectjx:"+hasApplyAspectjx(project))
}

}

}
})

0 comments on commit 6596fcb

Please sign in to comment.