Skip to content

Commit 4dea4a4

Browse files
authored
Merge pull request #40 from wyjsonGo/develop
publish v2.4.6 `GoRouter.getInstance().inject(this)`方法删除过时标记
2 parents ad85e8b + b674474 commit 4dea4a4

File tree

7 files changed

+30
-32
lines changed

7 files changed

+30
-32
lines changed

GoRouter-Annotation/src/main/java/com/wyjson/router/annotation/Param.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.wyjson.router.annotation;
22

33
import static java.lang.annotation.ElementType.FIELD;
4-
import static java.lang.annotation.RetentionPolicy.SOURCE;
4+
import static java.lang.annotation.RetentionPolicy.CLASS;
55

66
import java.lang.annotation.Retention;
77
import java.lang.annotation.Target;
88

99
@Target({FIELD})
10-
@Retention(SOURCE)
10+
@Retention(CLASS)
1111
public @interface Param {
1212
/**
1313
* Mark param name

GoRouter-Api/src/main/java/com/wyjson/router/GoRouter.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -288,67 +288,54 @@ public String getCurrentPath(Fragment fragment) {
288288
return RouteCenter.getCurrentPath(fragment);
289289
}
290290

291-
@Deprecated
292291
public void inject(Activity activity) {
293292
inject(activity, null, null, false);
294293
}
295294

296-
@Deprecated
297295
public void inject(Activity activity, Intent intent) {
298296
inject(activity, intent, null, false);
299297
}
300298

301-
@Deprecated
302299
public void inject(Activity activity, Bundle bundle) {
303300
inject(activity, null, bundle, false);
304301
}
305302

306-
@Deprecated
307303
public void inject(Fragment fragment) {
308304
inject(fragment, null, null, false);
309305
}
310306

311-
@Deprecated
312307
public void inject(Fragment fragment, Intent intent) {
313308
inject(fragment, intent, null, false);
314309
}
315310

316-
@Deprecated
317311
public void inject(Fragment fragment, Bundle bundle) {
318312
inject(fragment, null, bundle, false);
319313
}
320314

321-
@Deprecated
322315
public void injectCheck(Activity activity) throws ParamException {
323316
inject(activity, null, null, true);
324317
}
325318

326-
@Deprecated
327319
public void injectCheck(Activity activity, Intent intent) throws ParamException {
328320
inject(activity, intent, null, true);
329321
}
330322

331-
@Deprecated
332323
public void injectCheck(Activity activity, Bundle bundle) throws ParamException {
333324
inject(activity, null, bundle, true);
334325
}
335326

336-
@Deprecated
337327
public void injectCheck(Fragment fragment) throws ParamException {
338328
inject(fragment, null, null, true);
339329
}
340330

341-
@Deprecated
342331
public void injectCheck(Fragment fragment, Intent intent) throws ParamException {
343332
inject(fragment, intent, null, true);
344333
}
345334

346-
@Deprecated
347335
public void injectCheck(Fragment fragment, Bundle bundle) throws ParamException {
348336
inject(fragment, null, bundle, true);
349337
}
350338

351-
@Deprecated
352339
private <T> void inject(T target, Intent intent, Bundle bundle, boolean isCheck) throws ParamException {
353340
RouteCenter.inject(target, intent, bundle, isCheck);
354341
}

README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ dependencyResolutionManagement {
6969
}
7070
7171
dependencies {
72-
api 'com.github.wyjsonGo.GoRouter:GoRouter-Api:2.4.5'
72+
api 'com.github.wyjsonGo.GoRouter:GoRouter-Api:2.4.6'
7373
}
7474
// Kotlin配置参见8-1
7575
```
@@ -89,7 +89,7 @@ android {
8989
}
9090
9191
dependencies {
92-
annotationProcessor 'com.github.wyjsonGo.GoRouter:GoRouter-Compiler:2.4.5'
92+
annotationProcessor 'com.github.wyjsonGo.GoRouter:GoRouter-Compiler:2.4.6'
9393
}
9494
```
9595

@@ -157,7 +157,7 @@ pluginManagement {
157157
// 项目根目录下的build.gradle
158158
buildscript {
159159
dependencies {
160-
classpath 'com.github.wyjsonGo.GoRouter:GoRouter-Gradle-Plugin:2.4.5'
160+
classpath 'com.github.wyjsonGo.GoRouter:GoRouter-Gradle-Plugin:2.4.6'
161161
}
162162
}
163163
```
@@ -625,7 +625,7 @@ GoRouter.getInstance().build("/user/info/activity").putTag(3).commitActivity(Use
625625
// 动态注册Fragment
626626
GoRouter.getInstance().build("/new/param/fragment").putInt("age").putString("name").commitFragment(ParamFragment.class);
627627

628-
// 自动注入参数(2.3.2版本起,使用此方法需要在参数加上@Keep注解)
628+
// 自动注入参数(开启混淆的情况下,使用此方法需要配置混淆规则,参考8-7)
629629
GoRouter.getInstance().inject(this);
630630
```
631631

@@ -866,11 +866,11 @@ UserSignInActivityGoRouter.build()
866866
最早设计的是整个项目生成一个`GoRouterHelper.java`类,调用上比现在的每个页面生成一个对应的帮助类会更统一,
867867
但是这样会导致多人开发每个人生成的`GoRouterHelper.java`类代码合并冲突,所以想到把`GoRouterHelper.java`存放到根项目`build`目录,
868868
存放到`build`目录确实可以解决代码冲突问题,但是新的问题也来了,在首次开启生成帮助类的功能,项目里还没有调用这个`GoRouterHelper.java`类的时候是不会有问题的,
869-
如果项目里已经使用了这个帮助类,`build`目录被清除或者重新clone代码,这时项目就没法运行了,因为缺少这个帮助类。
869+
如果项目里已经使用了这个帮助类,`build`目录被清除或者重新clone代码,此时项目就没法运行了,因为缺少这个帮助类。
870870
这里不得不说一下帮助类生成流程和Android`buildConfig`任务的执行顺序,正常项目clone下来,idea提示报错缺少`buildConfig.java`类,
871871
你去`build`项目,Gradle会执行`buildConfig`任务,生成缺少的`buildConfig.java`类,再去生成common模块aar。
872872
路由帮助类在根项目里还不知道上层其他模块里有什么页面和服务的时候,它的执行顺序是,先`build`出来common模块,在去`build`其他页面业务模块,
873-
最后在app项目汇总,这时知道了所有页面和服务去生成帮助类到根模块项目。说回刚才的话题,项目里使用了帮助类,而帮助类又存放到`build`里,
873+
最后在app项目汇总,此时知道了所有页面和服务去生成帮助类到根模块项目。说回刚才的话题,项目里使用了帮助类,而帮助类又存放到`build`里,
874874
此时要是缺少了`build`目录,会导致项目无法运行,其实有其他方案解决这个问题,但都不是很好,
875875
所以最后我把这些帮助类存放到了`根项目/src/main/java/com/wyjson/router/helper/...`目录下,按照页面和服务生成对应的帮助类,
876876
解决了多人开发代码冲突的问题。虽然这些类不在`build`目录里,也不用担心无用的类,框架在每次生成新的代码的时候会自动删除无用的类,
@@ -894,7 +894,7 @@ kapt {
894894
}
895895

896896
dependencies {
897-
kapt 'com.github.wyjsonGo.GoRouter:GoRouter-Compiler:2.4.5'
897+
kapt 'com.github.wyjsonGo.GoRouter:GoRouter-Compiler:2.4.6'
898898
}
899899
```
900900

@@ -927,16 +927,23 @@ module_kotlin模块Demo示例[module_kotlin/build.gradle](https://github.com/wyj
927927
928928
##### 7. 混淆
929929
930-
框架已经做了混淆处理,开发者无需关心。如果使用了`GoRouter.getInstance().inject(this)`方法,2.3.2版本起,使用此方法需要在参数加上`@Keep`注解。
930+
框架已经做了混淆处理,开发者无需关心。
931+
932+
```pro
933+
# 如果使用了 GoRouter.getInstance().inject(this) 方法,需添加下面规则,保护字段
934+
-keepclassmembers class * {
935+
@com.wyjson.router.annotation.Param <fields>;
936+
}
937+
```
931938
932939
##### 8. `inject()`工作原理
933940
934941
* 2.3.2版本之前,`GoRouter.getInstance().inject(this)`方法会先通过`this`参数拿到`bundle`对象,再去获取当前页面的`path`,通过`path`拿到`CardMeta`数据,利用java反射进行数据的绑定。
935-
* 2.3.2版本起,`GoRouter.getInstance().inject(this)`方法废弃,使用`@Param`注解会自动生成参数注入类,内部代码是原生写法,性能更好,参见4-2。
942+
* 2.3.2版本起,使用`@Param`注解会自动生成参数注入类,内部代码是原生写法,性能更好,使用方法参见4-2。
936943
937944
##### 9. `go()`无参方法
938945
939-
如果你没有使用自动加载路由表方法`GoRouter.autoLoadRouteModule(this)`,也没有使用多模块application`GoRouter.callAMOnCreate(this)`方法,这时你去使用`go()`无参方法需要在application里调用`GoRouter.setApplication(...)`设置一个上下文。
946+
如果你没有使用自动加载路由表方法`GoRouter.autoLoadRouteModule(this)`,也没有使用多模块application`GoRouter.callAMOnCreate(this)`方法,此时你去使用`go()`无参方法需要在application里调用`GoRouter.setApplication(...)`设置一个上下文。
940947
941948
##### 10. 开启调试,查看日志可以检查使用java方式注册的路由是否有重复提交的情况
942949

app/proguard-rules.pro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
# # ########## Gson # end ##########
6767

6868

69+
# 如果使用了 GoRouter.getInstance().inject(this) 方法,需添加下面规则,保护字段
70+
-keepclassmembers class * {
71+
@com.wyjson.router.annotation.Param <fields>;
72+
}
6973

7074

7175

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
33
dependencies {
4-
classpath "com.github.wyjsonGo.GoRouter:GoRouter-Gradle-Plugin:${VERSION}"
4+
// classpath "com.github.wyjsonGo.GoRouter:GoRouter-Gradle-Plugin:${VERSION}"
55
}
66
}
77

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ android.nonTransitiveRClass=true
2525
# org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
2626

2727
GROUP_ID=com.github.wyjsonGo.GoRouter
28-
VERSION=2.4.5
28+
VERSION=2.4.6

settings.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ dependencyResolutionManagement {
1818

1919
rootProject.name = "GoRouter"
2020

21-
include ':app'
22-
include ':module_main'
23-
include ':module_user'
24-
include ':module_kotlin'
25-
include ':module_common'
21+
//include ':app'
22+
//include ':module_main'
23+
//include ':module_user'
24+
//include ':module_kotlin'
25+
//include ':module_common'
2626

2727
include ':GoRouter-Api'
2828
include ':GoRouter-Annotation'

0 commit comments

Comments
 (0)