Project Description:
Speed-tools is a proxy-mode-based dynamic deployment APK Hot update framework, plug-in development framework;
Speed-tools This name mainly refers to the quick iteration of the xxx tool set meaning.
Functions and Features:
1. Support Android version 2.3 or above
2, support the R file resource direct call
3. No launch calls during the development process
4, APK does not need to install direct call
5, Agent mode is less intrusive to code
6, simple to use, only need to inherit the simple class can
How to use
Add Dependencies:
compile ‘com.liyihangjson:speed_tools:1.0.3‘
First look at the project structure:
Lib_speed_tools: Plugin core function library
Module_host_main: Host Project master project, responsible for loading the deployment apk
Module_client_one: Testing Business APK 1
Module_client_two: Testing Business APK 2
Lib_img_utils: Test Imageloader picture Frame
Note: You need to use speed tools only to rely on Lib_speed_tools, and then start configuring the plug-in steps:
First, create the business logic class in Module_client_one: Testclass.java
/** * by liyihang */public class TestClass extends SpeedBaseInterfaceImp { private Activity activity; @Override public void onCreate(Bundle savedInstanceState, final Activity activity) { this.activity=activity; activity.setContentView(R.layout.activity_client_main); activity.findViewById(R.id.jump).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SpeedUtils.goActivity(activity,"first_apk", "two_class"); } }); ImageView imageView= (ImageView) activity.findViewById(R.id.img_view); imageView.setVisibility(View.VISIBLE); ImgUtils.getInstance(activity).showImg("http://img.my.csdn.net/uploads/201309/01/1378037235_3453.jpg", imageView); }}
Speedbaseinterfaceimp The Business Activity proxy class in the business component, he implements the primary life-cycle approach, which is equivalent to the activity class of the component.
Then create the Hock class to create only one of each business component: Clientmainactivity.java
public class ClientMainActivity extends SpeedClientBaseActivity { @Override public SpeedBaseInterface getProxyBase() { return new TestClass(); }}
This class is unique in the component, and is used by hock when it comes to independent testing.
Next configure the configuration component's Androidmanifest.xml
<application android:allowbackup= "true" android:icon= "@mipmap/ic_launcher" android:label= "@str Ing/app_name "android:supportsrtl=" true "android:theme=" @style/speedtheme "> <!--must be set root_class- -<meta-data android:name= "Root_class" android:value= "Com.example.clientdome.TestClass "/> <meta-data android:name=" Two_class "android:value=" Com.example.clientdome.TwoClass "/> <activity android:name=". Clientmainactivity "Android:theme=" @style/speedtheme "> <intent-filter> <a ction android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.category.LA Uncher "/> </intent-filter> <!--components Intent--<intent-filter> <data android:scheme= "Speed_tools" android:host= "sijienet.com" android:path= "/find_class "/> <action android:name=" Android.intent.action.VIEW "/> <category android:name = "Android.intent.category.DEFAULT"/> </intent-filter> </activity> </application>
Component intent to write dead remains, Root_class is called after death is used for the configured Com.example.clientdome.TestClass business class. This completes the business component configuration.
Next configure the host project Module_host_main;
Create a host project unique Hock class: Apkactivity.java
/** * by liyihang * blog http://sijienet.com/ */public class ApkActivity extends SpeedHostBaseActivity { @Override public String getApkKeyName() { return HostMainActivity.FIRST_APK_KEY; } @Override public String getClassTag() { return null; }}
The entire host project creates a class, the user is hock activity, and then creates an open page apk the first time it takes time to load, it is very appropriate to put on the open screen waiting page.
Hostmainactivity.java
/** * by Liyihang * Blog http://sijienet.com/*/public class Hostmainactivity extends Appcompatactivity implements Runna Ble,handler.callback, View.onclicklistener {public static final String first_apk_key= "first_apk"; public static final String two_apk_key= "other_apk"; Private Handler Handler; Private TextView Showfont; Private ProgressBar ProgressBar; Private Button openoneapk; Private Button opentwoapk; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_host_main); Showfont= (TextView) Findviewbyid (R.id.show_font); Progressbar= (ProgressBar) Findviewbyid (R.id.progressbar); openoneapk= (Button) Findviewbyid (r.id.open_one_apk); opentwoapk= (Button) Findviewbyid (r.id.open_two_apk); Handler=new handler (this); New Thread (This). Start (); } @Override public void Run () {String s = "module_client_one-release.apk"; String dexoutpath= "Dex_output2"; File Nativeapkpath = Speedutils.getnativeapkpath (Getapplicationcontext (), s); Speedapkmanager.getinstance (). loadapk (First_apk_key, Nativeapkpath.getabsolutepath (), DexOutPath, this); String s2 = "module_client_two-release.apk"; String dexoutpath2= "DEX_OUTPUT3"; File nativeApkPath1 = Speedutils.getnativeapkpath (Getapplicationcontext (), S2); Speedapkmanager.getinstance (). loadapk (Two_apk_key, Nativeapkpath1.getabsolutepath (), dexOutPath2, this); Handler.sendemptymessage (0x78); } @Override public boolean handlemessage (Message message) {Showfont.settext ("current host apk\n plugin apk complete"); Progressbar.setvisibility (View.gone); Openoneapk.setvisibility (view.visible); Opentwoapk.setvisibility (view.visible); Openoneapk.setonclicklistener (this); Opentwoapk.setonclicklistener (this); return false; } @Override public void OnClick (View v) {if (v.geTId () ==r.id.open_one_apk) {speedutils.goactivity (this, first_apk_key, null); } if (V.getid () ==r.id.open_two_apk) {speedutils.goactivity (this, two_apk_key, null); } }}
Load APK core code is:
String s = "module_client_one-release.apk"; String dexOutPath="dex_output2"; File nativeApkPath = SpeedUtils.getNativeApkPath(getApplicationContext(), s); SpeedApkManager.getInstance().loadApk(FIRST_APK_KEY, nativeApkPath.getAbsolutePath(), dexOutPath, this);
The business apk is placed in the assets directory. Finally configure the Androidmanifest.xml file:
<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "package=" Com.example.hostproject "> <uses-permission android:name=" Android.permission.INTERNET "/ > <uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/> <application androi D:allowbackup= "true" android:icon= "@mipmap/ic_launcher" android:label= "@string/app_name" Android:supp Ortsrtl= "true" android:theme= "@style/speedtheme" > <!--start activity loading apk--> <activity Andro Id:name= ". Hostmainactivity "> <intent-filter> <action android:name=" Android.intent.action.MAIN " /> <category android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </activity> <!--components hack--> <activity android:name= ". Apkactivity "android:label=" @string/app_name " Android:theme= "@style/speedtheme" > <intent-filter> <data android:scheme= " Speed_tools "android:host=" sijienet.com "android:path="/find_class "/> <action android:name=" android.i Ntent.action.VIEW "/> <category android:name=" Android.intent.category.DEFAULT "/> </in Tent-filter> </activity> </application></manifest>
This completes the configuration of all configurations, and the plug-in implementation.
Github:https://github.com/jasonliyihang/speed_tools
One voyage
Android Plugin Framework Speed-tools