Android uses dynamic onboarding framework DL for plug-in development

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-weight: bold;">If reproduced, please declare the source: time of the sand: </span>http://blog.csdn.net/t12x3456 (from The sands of the CSDN Blog)<br><br></p></p><p><p>Overview:<br></p></p><p><p>As the application continues to Iterate. The size of the application is increasing, the project becomes more and more bloated, and redundancy is added. new features of the project can not be identified with the user matching, serious anomalies often reaching, only emergency release of the patch version Number. Force the user to Update. results are frequently updated, but easy to reduce user stickiness. or is the Company's business development, the use of the same system more and more, the traditional way through the largest number of users of the main project to download and Install.</p></p><p><p>What to do?</p></p><p><p>Browser-plugin Development Mode:<br></p></p><p><p>A. To be able to split your Application.  Some features can be implemented in Plug-ins and then downloaded and not Installed. Assuming that there are new features to join, no need to update the application, just to reserve the plug-in management, we can join the plug-in way. Dynamically update your app, which needs to be improved or expanded, and the plugin can be updated without frequent installation or uninstallation (user aversion is easy).<br></p></p><p><p>Two. corresponding to the same system application, the normal drainage method can only guide users to download and install new applications, assuming the use of plug-in development, there is no need to install the application, close the plug-in function is also very convenient, eliminating the application installation and uninstallation process, to achieve seamless drainage.<br></p></p><p><p>Here we recommend an open source Dynamic onboarding Framework dl, which was launched by singwhatiwanna, and now has three people in Common. I was fortunate to be among the Contributor.<br></p></p><p><p>Let's say you're not familiar with the DL dynamic onboarding Framework. It is recommended to take a look at this article first:</p></p><p><p>APK dynamic load frame DL parsing http://blog.csdn.net/singwhatiwanna/article/details/39937639</p></p><p><p><strong>Let's say you see a panorama of the DL plugin framework, such as the following</strong></p></p><p><p><br></p></p><p><p><strong>Here I would mainly introduce you to the detailed steps of developing with the DL Framework:</strong></p></p><p><p><strong>1. First we need to get the project code from github:</strong></p></p><p><p>https://github.com/singwhatiwanna/dynamic-load-apk</p></p><p><p>Here we can see the downloaded folder such as the following</p></p><p><p></p></p><p><p>watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvddeyedm0nty=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "/></p></p><p><p><br></p></p><p><p>Lib folder is our public plug-in library<br></p></p><p><p>The sample folder is the corresponding demo, and the detailed project can participate in the above three modes in the DL Panorama:</p></p>Because of the general Project. The Code management and development team is relatively independent, and the General Plug-in project team is very difficult to access the code of the main project Team. therefore, This is primarily the first and most recommended way to develop with plugins that do not rely on hosting. There is no need for two teams to have too much interaction, and the development efficiency is relatively high.<br><p><p><strong><br></strong></p></p><p><p><strong>2 Import the libproject, as seen in the Following:</strong></p></p><p><p><br></p></p><p><p></p></p><p><p><br></p></p><p><p>Be able to see the Dl-lib.jar under the bin folder, assuming we need to change the Libproject. Once again, build to get the corresponding Dl-lib.jar can</p></p><p><p><strong><br></strong></p></p><p><p><strong>3. Plug-in Project development, import Main-pluginproject in Demo</strong></p></p><p><p><br></p></p><p><p>The first step is to emphasize the plug-in development considerations to avoid unnecessary errors<br></p></p><p><p>The plugin also needs to refer to the Dl's jar Package. however, You cannot put the following in the Libs folder of the plugin project, in other words, the plugin is compiled with the jar package but not the jar when packaged as an APK. Dl-lib.jar already exists in host project, and if there is a jar package in the plug-in, a class link error occurs. The reason is very easy. There are two copies of the same class in Memory. Again and Again. As for support-v4, the same is True.</p></p><p><p>Very easy for Eclipse. You just need to create a folder in plug-in Project. For example external-jars, then put Dl-lib.jar and Support-v4.jar in. At the same time, add the following two sentences to The. classpath<span style="white-space:pre"> </span> , for Example:</p></p><pre code_snippet_id="489273" snippet_file_name="blog_20141020_1_8274762" name="code" class="java"><pre code_snippet_id="489273" snippet_file_name="blog_20141020_1_8274762" name="code" class="java"><classpathentry kind= "lib" path= "external-jars/dl-lib.jar"/><classpathentry kind= "lib" path= " External-jars/android-support-v4.jar "/></pre></pre>Then the detailed steps in the plug-in development<p><p><strong>(1) assuming that the original activity, here needs to inherit dlbasepluginactivity, assuming that the original is fragmentactivity, then need to inherit dlbasepluginfragmentactivity, for Example</strong></p></p><p><p></p></p><pre code_snippet_id="489273" snippet_file_name="blog_20141020_2_3027115" name="code" class="java"><pre code_snippet_id="489273" snippet_file_name="blog_20141020_2_3027115" name="code" class="java"></pre></pre><pre code_snippet_id="489273" snippet_file_name="blog_20141020_3_5992718" name="code" class="java"><pre code_snippet_id="489273" snippet_file_name="blog_20141020_3_5992718" name="code" class="java">Testfragmentactivity extends Dlbasepluginfragmentactivity</pre></pre><br><strong><strong>(2) assume that the plug-in installation is required to execute, just put the jar below libs, if supported dynamic Loading. Still need to add exteral-jars in accordance with the above precautions<br></strong></strong><p><p></p></p><p><p><strong>(3) the permissions required by the plugin need to be declared in the host project</strong></p></p><p><p>Hypothesis is the actual development, generally to get the plugin from the server, here we are convenient to debug the demo, will be executed to generate the corresponding plug-in apk, into the SD card in the Dynamicloadhost folder<br></p></p><p><p><br></p></p><p><p><strong>4. Add the above generated Dl-lib.jar to Libs in host project, for example, the following see the host project provided in the demo</strong></p></p><p><p></p></p><p><p><br></p></p><p><p>In host project, first we need to get the plugin to call apk corresponding MAINACTIVITY,DL the plugin path to the SD card on the Dynamicloadhost folder, no words need to be created. Or make changes based on your NEEDS.<br></p></p><p><p><br></p></p><p><p></p></p><pre code_snippet_id="489273" snippet_file_name="blog_20141020_4_4780844" name="code" class="java"><pre code_snippet_id="489273" snippet_file_name="blog_20141020_4_4780844" name="code" class="java"> String Pluginfolder = environment.getexternalstoragedirectory () + "/dynamicloadhost"; File File = new file (pluginfolder); file[] plugins = File.listfiles (); if (plugins = = NULL | | plugins.length = = 0) { mnoplugintextview.setvisibility (view.visible); return; } For (File plugin:plugins) { pluginitem item = new Pluginitem (); Item.pluginpath = Plugin.getabsolutepath (); Item.packageinfo = Dlutils.getpackageinfo (this, item.pluginpath); If (item.packageInfo.activities! = null && item.packageInfo.activities.length > 0) { Item.launcheractivityname = item.packageinfo.activities[0].name; } Mpluginitems.add (item); }</pre></pre><br>Next is the apk that responds to the response, when you need to use Dl-lib.jar:<p><p></p></p><p><p><strong>(1) Get the Mainactivity class object in the plugin apk that we need to call by Class.forName</strong></p></p><p><p><strong>(2) As mentioned above, we need to infer whether the object inherits from Dlbasepluginactivity or dlbasepluginfragmentactivity, and gets the corresponding proxy class object</strong></p></p><p><p><strong>(3) use the corresponding proxy class object to adjust the plugin apk</strong><br></p></p><p><p></p></p><pre code_snippet_id="489273" snippet_file_name="blog_20141020_5_7746447" name="code" class="java">Pluginitem item = Mpluginitems.get (position); class<?<p><p></p></p><p><p>> proxycls = null; Try {class<?</p></p><p><p>> CLS = class.forname (item.launcheractivityname, false, dlclassloader.getclassloader (item.pluginpath , Getapplicationcontext (), getClassLoader ())); If (cls.assubclass (dlbasepluginactivity.class) = Null) {proxycls = dlproxyactivity.class; }} catch (classnotfoundexception e) {e.printstacktrace (); Toast.maketext (this, "load plugin apk failed, load class" + item.launcheractivityname + "failed.", Toast.length_short). Show (); } catch (classcastexception E) {//ignored} finally {if (proxycls = = Null) { Proxycls = dlproxyfragmentactivity.class; } Intent Intent = new Intent (this, proxycls); Intent.putextra (dlconstants.extra_dex_path, mpluginitems.get (position). pluginpath); StartActivity (intent); }</p></p></pre><br><p><p>finally, the host project<strong>Main-host</strong>is executed to see the final effect:</p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p>I believe that we have a certain understanding of the development of the DL dynamic loading framework through the above STEPS. now the DL framework is still expanding. We welcome the star,fork of our Project. Or make valuable suggestions. if you have any questions, please give us your feedback and we will fix or improve it in the version number:<br></p></p><p><p>https://github.com/singwhatiwanna/dynamic-load-apk</p></p><p><p><br></p></p> <p><p>Android uses dynamic onboarding framework DL for plug-in development</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.