-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote2_forRN.gradle
265 lines (230 loc) · 9.01 KB
/
remote2_forRN.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
def isRelease(){
for (String s : gradle.startParameter.taskNames) {
if (s.contains("ultiChannel") | s.contains("elease")) {
return true
}
}
return false
}
rootProject.buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10'
}
}
def isTest(){
for (String s : gradle.startParameter.taskNames) {
if (s.contains("ommon") | s.contains("est")) {
return true
}
}
return false
}
def hasApplyAspectjx(Project project0){
return project0.plugins.findPlugin("com.hujiang.android-aspectjx") != null || project0.plugins.findPlugin("android-aspectjx") != null
}
def isLocal(){
for(Project p : subprojects){
if( p.getName().contains("flipper")){
return true;
}
}
return false;
}
def doUseAspectjx(){
try {
return flipper_use_aspectjx.toBoolean()
}catch(Throwable throwable){
throwable.printStackTrace()
return false;
}
/*if( gradle.hasProperty("flipper_use_aspectjx")){
println("<--------has prop:flipper_use_aspectjx:"+gradle.getProperties().get("flipper_use_aspectjx"))
return gradle.getProperties().get("flipper_use_aspectjx").toBoolean();
}
println("<--------dont have prop flipper_use_aspectjx");
return false;*/
}
//println("<--------flipper_use_aspectjx 直接取 :"+doUseAspectjx());
//println("<--------flipper_use_aspectjx 从gradle.getProperties()里取:"+gradle.getProperties().get("flipper_use_aspectjx"));
def flipper
def flippernoop
if(isLocal()){
flipper = project(':flipper')
flippernoop = project(':flipper-no-op')
}else {
flipper = 'com.github.hss01248.flipperUtil:flipper:1.3.9'
flippernoop = 'com.github.hss01248.flipperUtil:flipper-no-op:1.3.9'
}
gradle.addBuildListener(new BuildListener() {
@Override
void buildStarted(Gradle gradle) {
}
@Override
void settingsEvaluated(Settings settings) {
println("---->settingsEvaluated:"+settings)
}
@Override
void projectsLoaded(Gradle gradle) {
println("---->projectsLoaded:"+gradle)
}
@Override
void projectsEvaluated(Gradle gradle) {
println("---->projectsEvaluated:"+gradle)
}
@Override
void buildFinished(BuildResult buildResult) {
}
})
gradle.addProjectEvaluationListener(new ProjectEvaluationListener() {
@Override
void beforeEvaluate(Project project) {
println("---->beforeEvaluate:"+project)
//println("---->beforeEvaluate:"+project.plugins)
/*if(project.name.contains("app") || project.name.contains("demo")
|| project.name.contains("Demo") || project.name.contains("sample")
|| project.name.contains("Sample")){
}*/
/* if(mybeApp(project.displayName)){
project.dependencies {
if(!isRelease()){
project.dependencies {
implementation flipper
}
}else {
project.dependencies {
implementation flippernoop
}
}
}
}*/
}
@Override
void afterEvaluate(Project project, ProjectState projectState) {
println("---->afterEvaluate:"+project)
//todo 遗留问题 如果app工程本身apply了 aspectjx插件,那么因为这里的implementation flipper在工程的apply plugin aspectjx之后,
// 那么里面的okhttp切面无法被插件切入到,必须是在apply 插件之前.
// 可以选择自己添加依赖到工程的dependencies块里
if(project.plugins.findPlugin("com.android.application") != null){
project.repositories {
maven { url 'https://jitpack.io' }
mavenCentral()
google()
jcenter()
}
if(!isRelease()){
project.dependencies {
implementation (flipper){
exclude group: 'com.facebook.fbjni', module: 'fbjni'
}
if(!isLocal()){
api ('com.github.hss01248.flipperUtil:network:1.3.9'){
exclude group: 'com.facebook.fbjni', module: 'fbjni'
}
}
}
project.configurations {
all*.exclude group: 'me.weishu', module: 'free_reflection'
all*.exclude group: 'com.facebook.fbjni', module: 'fbjni'
all {
resolutionStrategy {
force "androidx.sqlite:sqlite-framework:2.1.0"
}
}
}
if(!isTest()){
project.dependencies {
//implementation('com.github.hss01248:ActivityTaskView:5.0.1')
}
}
}else {
project.dependencies {
implementation flippernoop
}
}
//UnsatisfiedLinkError: couldn't find DSO to load: libfbjni.so
//todo 判断: 如果(RN)工程本来有依赖 group: 'com.facebook.fbjni', module: 'fbjni-java-only',那么就排除module: 'fbjni'
//all*.exclude group: 'com.facebook.fbjni', module: 'fbjni'
//all*.exclude group: 'com.facebook.fbjni', module: 'fbjni-java-only'
println("---->isLocal():"+isLocal())
//
//一些中型工程项目使用aspctjx就很慢了,建议项目里使用自己的include
//&& doUseAspectjx()
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', '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'
//不使用include时,项目一大就很慢,分钟级别,所以提供开关
include 'okhttp3','com.hss01248.flipper'
}
}else {
println("not apply aspectjx ,not add flipper networkinterceptor to okhttpclient automatically," +
"because isRelease or hasApplyAspectjx before or flipper_use_aspectjx is not true :\n " +
"isRelease:"+isRelease()+",hasApplyAspectjx:"+hasApplyAspectjx(project)+",flipper_use_aspectjx:"+doUseAspectjx())
if(hasApplyAspectjx(project)){
println("to enable auto inject of aspectj to okhttpclientbulider to all libs,you should add implementation com.github.hss01248.flipperUtil:flipper:1.0.9 manually in depencies")
}
}
}
}
})
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
def mybeApp(name){
return name != null && ( name.contains("app") || name.contains("demo")
|| name.contains("Demo") || name.contains("ample") )
}
/*def mybeApp(name){
return name != null && ( name.contains("app") || name.contains("demo")
|| name.contains("Demo") || name.contains("ample") )
}
rootProject.subprojects {
println(project.plugins.findPlugin("com.android.application")+"---->"+project.displayName)
if(mybeApp(project.displayName)){
project.dependencies {
if(!isRelease()){
project.dependencies {
implementation flipper
}
}else {
project.dependencies {
implementation flippernoop
}
}
}
}
}*/