From 1ac9a4a4bbe06563aca44bfed3b6b5a00b91ee25 Mon Sep 17 00:00:00 2001 From: act262 Date: Tue, 26 Mar 2019 12:03:23 +0800 Subject: [PATCH] #649 --- app/externalDex/make_patchdex.sh | 5 +++ .../android/arouter/demo/MainActivity.java | 33 +++++++++++++++++++ .../demo/extrasdex/ExternalDexProvider.java | 10 ++++++ .../extrasdex/ExternalDexProviderImpl.java | 24 ++++++++++++++ app/src/main/res/layout/activity_main.xml | 8 +++++ .../android/arouter/core/LogisticsCenter.java | 18 ++++++++-- .../android/arouter/utils/ClassUtils.java | 7 +++- 7 files changed, 101 insertions(+), 4 deletions(-) create mode 100755 app/externalDex/make_patchdex.sh create mode 100644 app/src/main/java/com/alibaba/android/arouter/demo/extrasdex/ExternalDexProvider.java create mode 100644 app/src/main/java/com/alibaba/android/arouter/demo/extrasdex/ExternalDexProviderImpl.java diff --git a/app/externalDex/make_patchdex.sh b/app/externalDex/make_patchdex.sh new file mode 100755 index 00000000..1805843b --- /dev/null +++ b/app/externalDex/make_patchdex.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +dx --dex --output patch.dex classes + +adb push patch.dex /data/local/tmp/arouter/external/patch.dex \ No newline at end of file diff --git a/app/src/main/java/com/alibaba/android/arouter/demo/MainActivity.java b/app/src/main/java/com/alibaba/android/arouter/demo/MainActivity.java index 78e82dbe..5332432d 100644 --- a/app/src/main/java/com/alibaba/android/arouter/demo/MainActivity.java +++ b/app/src/main/java/com/alibaba/android/arouter/demo/MainActivity.java @@ -12,6 +12,8 @@ import android.view.View; import android.widget.Toast; +import com.alibaba.android.arouter.core.LogisticsCenter; +import com.alibaba.android.arouter.demo.extrasdex.ExternalDexProvider; import com.alibaba.android.arouter.demo.testinject.TestObj; import com.alibaba.android.arouter.demo.testinject.TestParcelable; import com.alibaba.android.arouter.demo.testinject.TestSerializable; @@ -21,7 +23,9 @@ import com.alibaba.android.arouter.facade.callback.NavCallback; import com.alibaba.android.arouter.launcher.ARouter; +import java.io.File; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -63,6 +67,8 @@ public void onClick(View v) { // 发阶段,线上开启调试模式有安全风险,可以使用BuildConfig.DEBUG // 来区分环境 ARouter.openDebug(); + // Add external dex( push your patch dex here) + LogisticsCenter.setExtraDexList(collectExtraDexPath("/data/local/tmp/arouter/external")); ARouter.init(getApplication()); break; case R.id.normalNavigation: @@ -152,6 +158,15 @@ public void onInterrupt(Postcard postcard) { .withObject("map", map) .navigation(); break; + + case R.id.loadExternalDexRoute: + // Before using outer route , you must make sure load your outer dex impl ... + + ARouter.getInstance() + .navigation(ExternalDexProvider.class) + .doSomethings(); + break; + case R.id.navByName: ((HelloService) ARouter.getInstance().build("/yourservicegroupname/hello").navigation()).sayHello("mike"); break; @@ -214,6 +229,24 @@ public void onInterrupt(Postcard postcard) { } } + private static List collectExtraDexPath(String... extraDexDir) { + List extraDexPaths = Collections.emptyList(); + if (extraDexDir != null) { + extraDexPaths = new ArrayList<>(); + + for (String dir : extraDexDir) { + File dexDir = new File(dir); + if (dexDir.exists() && dexDir.isDirectory()) { + File[] listFiles = dexDir.listFiles(); + for (File dexFile : listFiles) { + extraDexPaths.add(dexFile.getAbsolutePath()); + } + } + } + } + return extraDexPaths; + } + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); diff --git a/app/src/main/java/com/alibaba/android/arouter/demo/extrasdex/ExternalDexProvider.java b/app/src/main/java/com/alibaba/android/arouter/demo/extrasdex/ExternalDexProvider.java new file mode 100644 index 00000000..5b0e12cb --- /dev/null +++ b/app/src/main/java/com/alibaba/android/arouter/demo/extrasdex/ExternalDexProvider.java @@ -0,0 +1,10 @@ +package com.alibaba.android.arouter.demo.extrasdex; + +import com.alibaba.android.arouter.facade.template.IProvider; + +/** + * This is external dex + */ +public interface ExternalDexProvider extends IProvider { + void doSomethings(); +} diff --git a/app/src/main/java/com/alibaba/android/arouter/demo/extrasdex/ExternalDexProviderImpl.java b/app/src/main/java/com/alibaba/android/arouter/demo/extrasdex/ExternalDexProviderImpl.java new file mode 100644 index 00000000..a684b690 --- /dev/null +++ b/app/src/main/java/com/alibaba/android/arouter/demo/extrasdex/ExternalDexProviderImpl.java @@ -0,0 +1,24 @@ +package com.alibaba.android.arouter.demo.extrasdex; + + +import android.content.Context; +import android.widget.Toast; + +import com.alibaba.android.arouter.demo.extrasdex.ExternalDexProvider; +import com.alibaba.android.arouter.facade.annotation.Route; + +@Route(path = "/extras/external/patch/route") +public class ExternalDexProviderImpl implements ExternalDexProvider { + + private Context mContext; + + @Override + public void init(Context context) { + mContext = context; + } + + @Override + public void doSomethings() { + Toast.makeText(mContext, " Here will be used by hot swap code.", Toast.LENGTH_SHORT).show(); + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index d3a9f805..4fa59ec7 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -158,6 +158,14 @@ android:layout_height="wrap_content" android:onClick="onClick" android:text="依赖注入(参照代码)" /> + + +