Android plugin extension Series--package and application

Source: Internet
Author: User
<span id="Label3"></p>The <---extension is ultimately submitted to the server as a ". jar", as well as in accordance with our naming convention, the plugin_+ plug-and-go name. Where the plug-in name is consistent with the uexname in Plugin.xml. such as plugin_uexdemo.jar, and download management plugin Plugin_downloadermgr.jar etc.   ---> 1. Development environment Construction<p><p>Android's development environment is built primarily with the installation of the jdk, Eclipse, and Android Sdk.</p></p><p><p>You can also install the JDK directly, then go to the Android website to download the ADT package (HTTP://DEVELOPER.ANDROID.COM/TOOLS/INDEX.HTML) and unzip it.</p></p><p><p>The entire installation process is simple, and the following are the main verification of the JDK and Android SDK installation Success.</p></p>1.1. JDK Installation Verification<p><p>After the installation is complete, you can check that the JDK is installed Successfully. Open the cmd window and enter Java–version to view the version information for the JDK. A screen similar to the following shows that the installation was Successful:</p></p>1. Development of Extension plug-in 1.1.  Development process 1.1.1. Plug-in development basic process 1.1.1.1. Plug-in Development Foundation Engineering construction<p><p>Import Appcanbaseproject into eclipse, this project for the plug-in development of basic engineering, the project Res and Assets folder contains plug-in development of the necessary files, developers do not arbitrarily delete.</p></p>1.1.1.1. integrating code into the Appcan Foundation development Engineering 1.1.1.1.1. Plugin Entry class Writing<p><p>When writing plug-in code, there should be at least one entry class, and it should be explained that this class inherits the base class Euexbase class and implements or overrides the parent Class's related methods, and then we can write the code according to our own functional Requirements.</p></p><p><p>For example, in the entry class uexdemo, a method for opening the activity was written to open the written helloappcannative (please do it yourself, omitting the helloappcannative writing process).</p></p>1.1.1.1.1. Plugin configuration file Authoring<p><p>After the entry class is written, you want to invoke the method of the Portal class on the Web side, which requires a configuration file to Handle.</p></p><p><p>Notice that under the Res/xml folder of the project, there is a plugin.xml file, which is the bridge linking the plugin to the Web Page.</p></p><p><p></p></p><p><p>In the Plugin.xml file, the most external label is uniformly written as <uexplugins>, and the next configuration <plugin> tag, This tag contains two attributes,<em>className</em> The class name for the entry Class's package name, Uexname is an alias for the Ingress class. finally, you need to configure the child tag <method> the Name property of the child tag is the method already written in the entry class.</p></p><p><p>If you have more than one entry class, continue adding <plugin> tags.</p></p>1.1.1.1.1. HTML page Call plugin configuration<p><p>Both the Ingress class and the plug-in configuration file are configured, and you now need to invoke the method of the Ingress class on the HTML Page.</p></p><p><p>Note that under Project assets/widget/, there is a index.html file, which is the invocation entry for the ingress class.</p></p><p><p>Write code within the Web page to implement the method of invoking the activity within the Uexdemo entry Class:</p></p><p><p></p></p><p><p>Where the OnClick property value is: The alias of the Ingress Class. method name ().</p></p>1.1.1.1.1. androidmanifest.xml Configuration<p><p>Open the Appcanbaseproject project, developers do not change the name attribute in Androidmanifest application;</p></p><p><p>Plug-in entry activity also do not change, the program opens will default into this activity, pop-up assets/widget/index.html page.</p></p><p><p></p></p>1.1.1.2. Test Plug-ins<p><p>Right-click on the project and select "run as"---> "Android applicition"---> "run program" to jump to the following interface;</p></p><p><p>Click the button to implement the appropriate method for invoking the entry class.</p></p><p align="center"><p align="center"></p></p>1.1.2. Building a plug-in package<p><p>Plug-ins are designed to achieve cross-platform uniformity and implement features that cannot be implemented in some Web pages, and the final form of the plugin is. zip package, plug-ins are divided into two types: one for Appcan SDK Mobile application development system, and the other for Appcan 3.0 Ide.</p></p><p><p>1) how to generate the plug-in package for the Appcan SDK mobile app development system and the required files, please refer to "how to generate the Appcan SDK Mobile app development system plug-in package" BELOW.</p></p><p><p>2) How to use the Appcan 3.0 IDE plug-in package and the required files, please refer to "how to generate Appcan 3.0 IDE plug-in package" BELOW.</p></p><p><p></p></p>1.2. Naming conventions<p><p>Plug-in file naming can be arbitrary, but there is a unified naming convention in appcan, in order to maintain a consistent extension of the development should also conform to the naming Convention.</p></p>1.2.1. naming of classes and methods in Plugin.xml<p class="1" align="left"><p class="1" align="left">The Plugin.xml file is located in the XML directory under the Res directory and is an XML file that configures custom native plugin calling objects, and if custom objects and native plug-ins are required, you must configure the custom JS object name and the Java Class's package name Class name in this File. The following is an example of the Appcanbaseproject plugin:</p></p><p><p></p></p><p><p></p></p><p class="1"><p class="1"><strong>uexname</strong>: The name of the encapsulated JS object, beginning with the Uex prefix, which is the English name of the uex+ object;</p></p><p class="1"><p class="1"><strong>className</strong>: The path package name and the class name of the Java object mapped with the JS object are suggested to be named Euex prefix + name;</p></p><p><p><strong></strong>Methods: The name of the method in the plug-in object, still conform to the hump naming method, callback page function does not need to write to this file, but should be written into the API documentation of the PLUG-IN.</p></p><p class="1"><p class="1"></p></p>1.2.2. Naming of Classes<p><p>The plug-in entry class has a naming prefix of euex, that is, the class naming convention is the English name of the euex+ object, such as euexdemo, such as the download management plugin Euexdownloadermgr we have Encapsulated. of course, This naming specification is not required, but it is important to ensure that the class name of the plug-in class is consistent with the class name in the Plugin.xml.</p></p>1.2.3. Naming of methods<p><p>The method name conforms to the hump naming method, such as creating the Download object "createdownloader" in the download connector, and downloading "download". It is worth noting that the method name here should be consistent with methods name under the corresponding class in plugin.xml, otherwise the call will Fail.</p></p>1.2.4. name of the jar package<p><p>The extension is eventually submitted to the server in the form of ". jar", as well as our naming convention, the plugin_+ plug-in Name. Where the plug-in name is consistent with the uexname in Plugin.xml. such as plugin_uexdemo.jar, and download management plugin Plugin_downloadermgr.jar etc.</p></p>1.2.5. Naming of resource files<p><p>Naming rules for Plugin_+plugin object names _+ other information, such as plugin_uexdemo_xxx.png, plugin_uexdemo_yyy.xml, <string name= "plugin_uexdemo_ ZZZ "> and so On.</p></p>1.3. Plug-in composition 1.3.1. Appcan SDK Mobile Application development system Plug-in package composition<p><p>Plugins are plugins that exist in the form of A. Zip file, which is then extracted as follows:</p></p><p><p></p></p><p><p></p></p><p><p>The Appcanbaseproject plugin contains files with plugin.xml, info.xml (AppCan3.0 new additions), androidmanifest.xml files, jar files, Res folder (if The plug-in uses a resource file, it needs to have a folder, it is not required).</p></p><p><p></p></p>1.3.1.1. plugin.xml File<p><p>Add the Plugin.xml file to the XML directory under the Res directory, filling in the classes, methods, and so on in the plug-in using the naming Convention. For example, appcanbaseproject project, using Uexdemo object name, startactivityforresult method, etc.</p></p><p><p></p></p>1.3.1.2. info.xml File<p><p>This file is a new file introduced by AppCan3.0, which is mainly used to describe plug-in version information and update Content. The contents of the Info.xml file are as Follows:</p></p><p><p></p></p><p><p></p></p><p><p>Uexname: represents the plug-in Name.</p></p><p><p>Version: represents the current plug-in revision number, and later through the Info.xml file can also know the current plug-in version Information.</p></p><p><p>Build: represents a small version of the current plug-in, used Internally.</p></p><p><p>Info: represents the current plug-in version modification information, later through the Info.xml file can also know the current plug-in this version of the modification Information.</p></p><p><p>This file is newly added and must be in AppCan3.0, please note to the Developer.</p></p>1.3.1.3. Androidmanifest.xml<p><p>Configure the activity, service, receiver permissions used in this plugin, and the properties of the app, such as screen start, and so On. Refer to the Androidmanifest.xml file in the Appcanbaseproject project.</p></p>1.3.1.4. jar Folder<p><p>This contains the plugin jar package, which is the necessary file for the upload of the plugin Package.</p></p>1.3.2. Appcan 3.0 IDE Plug-in package consists of 1.3.2.1. Plugin.xml file<p><p>Plugin.xml in the plug-in with the Appcan SDK Mobile application development System.</p></p>1.3.2.2. info.xml File<p><p>Info.xml in the plug-in with the Appcan SDK Mobile application development System.</p></p>1.3.2.3. Androidmanifest.xml<p><p>Androidmanifest.xml in Plug-ins with Appcan SDK Mobile application development system</p></p>1.3.2.4. jar Folder<p><p>The Jar folder in the Appcan SDK mobile app development system Plugin.</p></p>1.3.2.5. Dex Folder<p><p>This folder holds the jar packages available in the Appcan 3.0 ide, which is the prerequisite for the Appcan 3.0 IDE to build the installation package (note to the developer).</p></p><p><p>How to build the jar packages available for the Appcan 3.0 ide, refer to "generating jar packages available for Appcan 3.0 ide" below.</p></p>1.4. Detailed introduction of plugin code<p><p>When writing plug-in code, there should be at least one entry class, provided to the front-end, which inherits Plugin's underlying class Euexbase class, then implements or overrides the related function, and adds a custom interface method corresponding to methods in Plugin.xml. For common issues you may encounter in developing plug-ins, see the FAQ section of plug-in development later in this Article.</p></p>1.4.1. writing the base class<p><p>The interfaces inherited in the code mainly include the following 3:</p></p><p><p><strong>Euexbase.java</strong>:</p></p><p><p>It encapsulates the parent class of the bridge function that JS calls native and native callback js, and any object of the native extension needs to inherit this class;</p></p><p><p><strong>Euexutil.java</strong> <strong>:</strong></p></p><p><p>Provides a tool class for dynamically acquiring features such as this app resource ID.</p></p><p><p><strong>note:</strong> All resource files in appcan, including string resources, must be dynamically retrieved using the relevant functions in this tool class, not directly using R file references! Refer to "how to invoke resources in res" below for specific usage.</p></p><p><p>Euexcallback.java<strong>:</strong></p></p><p><p>Some constants related to Plugin's callback are no longer enumerated and can be viewed on their own.</p></p>1.4.2. defining Java Classes with JS object mappings<p><p>New Java class Uexdemo.java and inherits from Euexbase.</p></p><p><p></p></p><p><p>The rest of the project is written according to the development requirements of the plug-in, but pay attention to naming conventions.</p></p><p class="1" align="left"><p class="1" align="left">Where: all interface functions have parameters of 1 string arrays. The length of this array is the number of arguments that JS passes over, and the index of this array corresponds to the index of the parameter in Js.</p></p><p class="1" align="left"><p class="1" align="left">For example, there is a similar call in Js:</p></p><p class="1" align="left"><p class="1" align="left">Uexdemo.showinputdialog (p1,p2,p3,p4)</p></p><p class="1" align="left"><p class="1" align="left">well, when it maps to Uexdemo.java's:</p></p><p class="1" align="left"><p class="1" align="left">public void Showinputdialog (string[] Parm)</p></p><p class="1" align="left"><p class="1" align="left">function, the length of the parm will be 4, can be obtained by parm[0] [p1,parm[1] obtained p2,parm[2] obtained p3,parm[3] obtained p4, and so On.</p></p><p><p>:</p></p><p><p></p></p><p><p>Inheriting the Euexbase class must implement the clean method, which is the calling method of the platform encapsulation, releasing some memory related to the current page and so on when switching the Web page (refer to the Appcanbaseproject project).</p></p><p><p>Note that the clean<strong>(string[] Params)</strong> method is called automatically when the window is toggled, so you should not reclaim resources in this method if you want to keep some resources in different windows.</p></p>1.4.3. callback data to a Web page<p><p>Methods are divided into two main types:</p></p><p><p><strong>Standard callback Method:</strong></p></p><p><p>In the native extension of the Appcan platform, the recommended callback rule is Uexdemo.cbmethodname (opid,datatype,data), where opid represents an opcode-differentiated operation, and DataType is used to represent the type of Data. Data is a CALLBACK. This callback method can be implemented using the package method Jscallback provided by the PLATFORM.</p></p><p><p>Here is an example of returning JSON Data:</p></p><p><p></p></p><p><p><strong>Custom Callback Methods:</strong></p></p><p><p>In addition to using the standard callback method, you can also use a custom callback method, the number of parameters returned JS and the type can be customized as Needed. This callback method should be implemented using the package method OnCallback provided by the PLATFORM.</p></p><p><p>Here is an example of a custom callback:</p></p><p><p></p></p><p><p>Where Script_header is a constant in the euexbase, after inheritance can be used directly, convenient splicing JS string, can also write their own javascript: Instead. The following On_function_map_drag are pre-customized callback method names, in the same form as the standard callback methods above, with specific reference to the naming specification Description.</p></p><p><p></p></p>1.5. how to generate the Appcan SDK Mobile App development system plug-in Package<p><p>Appcan SDK Mobile Application development system plug-in package main Components:</p></p><p><p>Jar Folder:</p></p><p><p>Project SRC under all the classes out of the package file stored in this directory;</p></p><p><p>Res folder:</p></p><p><p>Copy the images, XML files, etc. (other than the resource files Appcanbaseproject the Project) from the plug-in project Res folder, and place them in the Res folder;</p></p><p><p>Androidmanifest.xml file:</p></p><p><p>The Androidmanifest.xml file of the plug-in project can be copied, see the following "androidmanifest.xml file configuration";</p></p><p><p>Plugin.xml file:</p></p><p><p>The plug-in project Res/xml under the PLUGIN.XM copy, the specific changes see above "plugin.xml class and method naming" introduction;</p></p><p><p>Info.xml file:</p></p><p><p>This file is a new file introduced by AppCan3.0, which is mainly used to describe plug-in version information and update Content.</p></p><p><p></p></p><p><p>A native plug-in package directory structure with resource files is typically similar to the following:</p></p><p><p></p></p><p><p>Where the jar directory is the directory where your jar files are stored, jar files, info.xml files, and The Plugin.xml file is required (if the jar package corresponds to a JNI interface, it contains so files), other plugins without resource files may not have a res directory or no androidmanifest.xml files.</p></p><p><p></p></p><p><p>The following is a detailed explanation of the corresponding directories and files in the plugin package:</p></p>1.5.1. jar Folder<p><p></p></p><p><p>This contains the plugin jar package, which is the necessary file for the upload of the plugin Package. Naming must conform to the naming convention, plugin_+ extension object name + specific suffix, such as: plugin_uexdemo.jar.</p></p><p><p>Make JAR package method: Check all package and class files under Plug-in project src, right-select excport--java--jar file, Select output path follow the prompts to Pack.</p></p>1.5.2. plugin.xml File Configuration<p><p>Plugin.xml is the required file for uploading, as described in the naming specification Above.</p></p>1.5.3. info.xml File Configuration<p><p>Info.xml is an essential file for Uploading. This file is a new file introduced by AppCan3.0, which is mainly used to describe plug-in version information and update Content. The contents of the Info.xml file are as Follows:</p></p><p><p></p></p><p><p></p></p><p><p>Uexname: represents the plug-in Name.</p></p><p><p>Version: represents the current plug-in revision number, and later through the Info.xml file can also know the current plug-in version Information.</p></p><p><p>Build: represents a small version of the current plug-in, used Internally.</p></p><p><p>Info: represents the current plug-in version modification information, later through the Info.xml file can also know the current plug-in this version of the modification Information.</p></p><p><p>This file is newly added and must be in AppCan3.0, please note to the Developer.</p></p>1.5.4. androidmanifest.xml Configuration<p><p>Androidmanifest.xml is a non-mandatory configuration file used to configure the activity,service,receiver, permissions, and so on in this native plugin. This plugin is only configured for this Purpose. Its structure is similar to:</p></p><p><p></p></p>1.5.5. Res folder<p><p>The Res folder is Non-mandatory and is used to store extensions-specific Resources. All directories in this directory correspond to the Res directory of the Appcanbaseproject Project. therefore, to place resources in the appropriate folder when committing, the naming should conform to the naming conventions mentioned Above. directory structure and Naming conventions example</p></p><p><p><br clear="all"></p></p><p><p><strong><br clear="all"></strong></p></p>1.6. How to build the Appcan 3.0 IDE plug-in package<p><p>Appcan SDK Mobile Application development system plug-in package main Components:</p></p><p><p>First unzip the existing standard plug-ins, you can see the directory structure of the plug-in as Shown:</p></p><p><p></p></p><p><p>where so folder and res folder is optional, if the plugin has its own developed NDK generated so files or Third-party so files, in the plug-in directory structure to create a new so folder, so file into the so folder, if the plugin does not reference so file, you do not need to create this folder. The jar folder is used to place its own exported jar files and Third-party jar files, The Res folder is used to place layout and resource files, the internal directory structure and the RES directory structure in Android native development are the Same. Androidmanifest files only need to write their own plug-in inside the code can be used, plugin inside to register plug-in Interface.</p></p><p><p>Create a new Dex folder under this directory structure to place the generated Appcan 3.0 IDE available jar Files:</p></p><p><p></p></p><p><p>First open a command prompt and go to the sdk\build-tools\android-4.3 path under the Android SDK Path:</p></p><p><p></p></p><p><p>Copy all of the jar files used by the plug-in (including the jar file that you exported locally) to this path: take the Uexflowdetection plugin as an example:</p></p><p><p></p></p><p><p>The plugin has a total of 4 jar files, including three third-party jar files and one locally exported jar file, editing commands:</p></p><p><p></p></p><p><p>Command explanation:</p></p><p><p>dx–dex–output= is the command header, is fixed, the command line Plugin_uexflowdetection_dex.jar is the bytecode file to generate, the naming format is plugin_uexxxx_dex.jar. The next four parameters are the 4 jar files used by the plug-in, the number of jar files used by the plug-in, followed by the name of the number of Jar Files.</p></p><p><p>Click Enter to generate the bytecode file, once generated:</p></p><p><p></p></p><p><p>The resulting bytecode file is within the red box.</p></p><p><p>Copy the bytecode file to the Dex folder created in step 2nd, and package the plugin to a APPCANSDK mobile app development system plug-in package that has been successfully built into a plug-in package that can be used Appcan 3.0 Ide.</p></p><p><p></p></p>2. Plug-in Development FAQ 2.1. How to add a window<p><p>In the Appcan platform, in order to facilitate the management window and the front-end JS interaction, the new activity should be used to convert the main activity to Activitygroup to manage the new activity opened by the Plug-in. The sample code is as Follows:</p></p><p><p></p></p>2.2. how to invoke a resource in res<p class="p0"><p class="p0">In Appcan plug-in development, you should not use R files in your app to refer to resource ids, which can create problems, and you should use the methods in the Platform-provided Euexutil class to get the corresponding IDs by resource Names. Examples are as Follows:</p></p><p class="p0"><p class="p0"></p></p><p class="p0"><p class="p0">Above is the reference control ID.</p></p><p class="p0"><p class="p0">correspondingly, There are methods such as getresdrawableid,getreslayoutid, which correspond to the common internal class one by one of the Android resource ID class r, as long as the file name of the corresponding resource is passed as a parameter (as with native development, do not fill in. xml. png, and so on, for this extension).</p></p>2.3. The plugin did not run correctly during the test<p class="p0"><p class="p0"><strong>Performance:</strong></p></p><p class="p0"><p class="p0">The engine error is prompted in eclipse, or the callback information from the native plugin to the front end cannot be Received.</p></p><p class="p0"><p class="p0"><strong>Possible causes:</strong></p></p><p class="p0"><p class="p0">1, plugin.xml File Configuration error (check classname and front-end call to use the name of the plug-in is consistent);</p></p><p class="p0"><p class="p0">2. Info.xml file Configuration error (this file is a new addition to the AppCan3.0 engine, it must be properly configured into the plug-in package and fill in the appropriate plug-in information, the detailed procedure refer to the Info.xml file described above);</p></p><p class="p0"><p class="p0">3. When passing JSON string parameters, it should be noted that the quotation marks that represent the JS string are best used in single quotation marks to prevent ambiguity with the double quotation marks in the JSON data, or the outer layer can be enclosed in double quotes, but the inner double quotes are escaped with "\";</p></p><p class="p0"><p class="p0">4, Clean () method for the engine to switch pages automatically, in which should not deal with some of the data sharing between the pages of the collection;</p></p><p class="p0"><p class="p0">5, to callback information in other activities or objects to the Web page, should not pass the plug-in object, you should define a callback interface and generate object completion callback Work.</p></p>2.4. Package application failed after plugin upload<p class="p0"><p class="p0"><strong>Performance:</strong></p></p><p class="p0"><p class="p0">Packaging failed in the Appcan SDK mobile app development System.</p></p><p class="p0"><p class="p0"><strong>Possible causes:</strong></p></p><p class="p0"><p class="p0">1, the resource files in the plug-in package is missing;</p></p><p class="p0"><p class="p0">2, the plug-in package structure error (must contain the necessary directory structure, Jar folder to have the reference jar package and so file, also should contain info.xml, plugin.xml);</p></p><p class="p0"><p class="p0">3. There are problems with the resource file (such as XML format error, 9patch picture making error, etc.).</p></p><p><p></p></p><p><p>Android plugin extension Series--package and application</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.