"Android XML" Android XML to Java Code series

Source: Internet
Author: User

Recently in the company to do a project, you need to pack the Android interface into the jar package for customer use. For most developers, the layout of the Android interface is based on an XML file and is dynamically tuned with a small amount of Java code. The code that is packaged into the jar package means that it is not possible to get resources quickly by means of regular getresources (), getString (), as these resources are initialized when the APK is installed. In order to meet the needs of customers, I began to look for a variety of solutions on the Internet. The results are as follows:

1.APK Bulk Package Implementation method: Install a new apk, the new apk and the main apk are connected using Android:shareduserid so that the main apk can get all the res resources of the new apk. Note that the value of r.id.xxx is the value of R.java in the new apk. So you need to get the r.class of the new apk or the value of the resources in the R.java of the new apk and the main apk is exactly the same, otherwise there will be a situation where the resource is not available. Conclusion: can be achieved, but need to install an APK. Installing the APK silently requires root privileges, or the installation screen will pop up. You haven't found a way to get resources without installing the APK.
Reference Link: http://blog.csdn.net/lg707415323/article/details/7709076 2.LayoutInflater scenario Implementation method: parsing external XML resources through the Layoutinflater class , and convert to the desired layout. Analysis: Android explained that for performance reasons, Layoutinflater only supports parsing XML that has been precompiled in the APK package. So there is no way to parse an externally imported XML layout resource. Conclusion: not feasible
Reference Link: http://gamebs.blog.163.com/blog/static/1860182182012827545621/
3.Android XML to Java Code scheme (open source/self-research) reference link: http://www.xmltojava.com/online Android xmtojaval conversion service, free, support various controls (HTTP/ www.xmltojava.com/page/controls/), support is rich, but there are some simple manual edits that are required to complete the conversion. Resource conversions under the drawable and values directories are not supported. Conclusion: The workload of manual translation can be reduced, but the demand cannot be solved completely. Esmanagertool uses a lot of custom drawable and strings, which need to be translated manually. Reference Link: https://github.com/bsp0911932 https://github.com/rvp2014/AndroidXMLToJavaConverter personal Open Source project, the first project written in PHP, the amount of code is very small , only updated once, should not be used. The second project is androidy application dynamic analysis, just built up, supported by a few fields, should also be useless. The completion level is very low. There are no proven solutions on Google or GitHub. Conclusion: The 4.zip package scheme can only replace the image resource, and the XML layout can't be resolved. (The skin-changing feature of the desktop app is based on the two scenarios of zip or APK) conclusion: not feasible
The 5.ClassLoader scheme loads the APK package ClassLoader and obtains resources through a reflection approach to various methods of activity or other components. Analysis: Practice finds that reflection invokes activityconclusion: not feasible
Reference Link: http://blog.csdn.net/mer1234567/article/details/7308855 Overall Conclusion: programme 1 is the most convenient, but the customer is not necessarily acceptable; Scenario 3 is more secure, but it is expensive.

Because scenario 1 requires the installation of the APK, root privileges are also required if you want to install silently. This scheme is too cumbersome to choose the way Android XML translates native code. So there is the birth of Androidxmltojava management tools.

The next few steps will share some of the resolution of the conversion tool. When the project is perfect, it will be put on the blog, now not released.

Copyright, reproduced Please specify the source:

Http://www.cnblogs.com/sickworm/p/4245089.html

"Android XML" Android XML to Java Code series

Related Article

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.