File tree Expand file tree Collapse file tree 6 files changed +35
-11
lines changed
rudolph/src/main/java/cn/wzbos/android/rudolph Expand file tree Collapse file tree 6 files changed +35
-11
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,8 @@ dependencies {
2020 annotationProcessor ' com.google.auto.service:auto-service:1.0-rc7'
2121 implementation ' org.apache.commons:commons-lang3:3.5'
2222 implementation ' org.apache.commons:commons-collections4:4.1'
23- implementation project(' :rudolph-annotations' )
24- // implementation "${publishedGroupId}:rudolph-annotations:${rudolph_version}"
23+ // implementation project(':rudolph-annotations')
24+ implementation " ${ publishedGroupId} :rudolph-annotations:${ rudolph_version} "
2525}
2626
2727apply from : ' ../install.gradle'
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ public class Rudolph {
2626 private static List <RouteInfo > routes = new ArrayList <>();
2727 private static Application app ;
2828 private static String scheme ;
29+ private static Boolean initialized = false ;
2930
3031 public static Application getApplication () {
3132 return app ;
@@ -40,6 +41,9 @@ public static String getScheme() {
4041 */
4142 public static void init (Application application ) {
4243 Log .v (TAG , "init" );
44+ if (initialized )
45+ return ;
46+
4347 app = application ;
4448 AssetManager assetManager = application .getResources ().getAssets ();
4549 try {
@@ -53,16 +57,23 @@ public static void init(Application application) {
5357 iGroupInstance .init (application );
5458 }
5559 } catch (ClassNotFoundException e ) {
56- Log .e (TAG , "初始化\" " + className + "\" 组件失败,请检查包名是否正确!" );
57- e .printStackTrace ();
60+ Log .e (TAG , "初始化\" " + className + "\" 组件失败,请检查包名是否正确!" , e );
5861 }
5962 }
6063 }
64+ initialized = true ;
6165 } catch (Exception e ) {
62- e . printStackTrace ( );
66+ Log . e ( TAG , "路由初始化异常!" , e );
6367 }
6468 }
6569
70+ /**
71+ * 获取是否已初始化路由表
72+ */
73+ public static Boolean isInitialized () {
74+ return initialized ;
75+ }
76+
6677 public static void setScheme (String schemeStr ) {
6778 scheme = schemeStr ;
6879 }
Original file line number Diff line number Diff line change 11package cn .wzbos .android .rudolph .router ;
22
3+ import android .util .Log ;
4+
35import cn .wzbos .android .rudolph .exception .RudolphException ;
46
57public class FragmentRouter <R > extends Router <R > {
@@ -34,7 +36,7 @@ public R open() {
3436
3537 return (R ) instance ;
3638 } catch (Exception e ) {
37- e . printStackTrace ( );
39+ Log . e ( "rudolph" , "open fragment error!" , e );
3840 if (callback != null )
3941 callback .onFailed (e );
4042 }
Original file line number Diff line number Diff line change 22
33import android .app .Application ;
44import android .content .Context ;
5+ import android .util .Log ;
56
67import cn .wzbos .android .rudolph .Rudolph ;
78import cn .wzbos .android .rudolph .Consts ;
@@ -79,7 +80,7 @@ public Object open(Context context) {
7980 }
8081
8182 } catch (Exception e ) {
82- e . printStackTrace ( );
83+ Log . e ( "rudolph" , "方法调用异常!" , e );
8384 if (null != callback )
8485 callback .onFailed (e );
8586 }
Original file line number Diff line number Diff line change @@ -331,7 +331,7 @@ private List<String> getSegments() {
331331 segments .add (URLDecoder .decode (val , "utf-8" ));
332332 }
333333 } catch (UnsupportedEncodingException e ) {
334- e . printStackTrace ( );
334+ Log . e ( "rudolph" , "getSegments failed!" , e );
335335 }
336336 }
337337 return segments ;
@@ -385,7 +385,7 @@ Map<String, String> getUriAllParams() {
385385 String value = URLDecoder .decode (kv [1 ], "utf-8" );
386386 params .put (name , value );
387387 } catch (Exception e ) {
388- e . printStackTrace ( );
388+ Log . e ( "rudolph" , "getUriAllParams failed!" , e );
389389 }
390390 }
391391 }
Original file line number Diff line number Diff line change 11package cn .wzbos .android .rudolph .router ;
22
33
4+ import android .util .Log ;
5+
6+ import java .lang .reflect .Constructor ;
7+
48import cn .wzbos .android .rudolph .IRouteService ;
59
610public class ServiceRouter <R extends IRouteService > extends Router <R > {
@@ -13,13 +17,19 @@ protected ServiceRouter(Builder builder) {
1317 super (builder );
1418 }
1519
20+
1621 @ Override
1722 public R open () {
1823 if (super .intercept (null ))
1924 return null ;
2025
2126 try {
22- Object instance = target .getConstructor ().newInstance ();
27+ Constructor <?> constructor = target .getConstructor ();
28+ if (!constructor .isAccessible ()) {
29+ Log .w ("rudolph" , target .getName () + " constructor method is private!" );
30+ constructor .setAccessible (true );
31+ }
32+ Object instance = constructor .newInstance ();
2333 if (instance instanceof IRouteService ) {
2434 IRouteService component = ((IRouteService ) instance );
2535 component .init (this .bundle );
@@ -28,7 +38,7 @@ public R open() {
2838 return (R ) component ;
2939 }
3040 } catch (Exception e ) {
31- e . printStackTrace ( );
41+ Log . e ( "rudolph" , "open service failed!" );
3242 if (callback != null )
3343 callback .onFailed (e );
3444 }
You can’t perform that action at this time.
0 commit comments