Stand on the shoulders of giants learn Android development

Source: Internet
Author: User

We know that the best way to learn at first is to imitate, especially to imitate giants. The imitation of Android development, then, is to analyze and study the layout and implementation of mainstream programs, and then improve their own technology.


The first trick----reverse engineering

To analyze the "giant" software, naturally unavoidable reverse engineering, will be the APK program into what we can see the source of understanding. This Google official has helped us to do the tool, Apktool is a good reverse tool.

is: Http://pan.baidu.com/s/1kTqRhaR

Let's take an example of analysis to illustrate the use of this tool:

You only need to execute the following command, that is, disassembly reverse work is done. The tool will generate the Weixin directory when finished.

Apktool Decode weixin.apk

In the directory, you can see the various resource files of the software, including the layout files. With these resource files, it is easy to make the same interface as you do, and of course the program focuses on the code logic, not the interface.

[email protected]:/tmp$ LS weixin/androidmanifest.xml apktool.yml assets lib Res smali[email protected] $ l                     S weixin/res/-A.                    Layout Values-id values-th. layout-hdpi values-in values-tranim layout-ldpi values-it values-v11color L ayout-mdpi values-iw values-v14drawable layout-v11 values-ja values-vidrawable-480dpi RA      W Values-ko values-w360dpdrawable-640dpi values Values-land values-w480dpdrawable-en-hdpi Values-ar values-large values-w500dpdrawable-hdpi values-de values-ldpi Values-w600dpdrawable-lan D values-en values-mdpi values-w720dpdrawable-land-hdpi values-es values-ms values-xhdpidrawabl e-mdpi values-fr values-pl values-xlargedrawable-xhdpi values-hdpi values-pt values-zh-rcnd     rawable-zh-rcn-hdpi Values-he Values-ru  VALUES-ZH-RTWDRAWABLE-ZH-RTW-HDPI Values-hi VALUES-SW600DP XML 

There is a Smali directory, it is the source directory, and this source code Smali is an intermediate language, it is neither the Java language, nor the assembly language of Java, but the Apktool tool can be recognized a special language. To further translate into the Java language, we can use both Dex2jar and Jd-gui tools.

Jd-gui:http://pan.baidu.com/s/1i3n7rpr

Dex2jar:http://pan.baidu.com/s/1b2lmy

The specific commands are as follows:

MV weixin.apk Weixin.zipunzip-o weixin.zip//extracted and got Classes.dex file dex2jarrootpath/dex2jar.sh classes.dex// Then you get the Classes_dex2jar.jar file Jd-gui Classes_dex2jar.jar

At the same time, the user can modify the Smali file and then re-generate the APK with Apktool. You must download another tool before using this command Aapt,apktool will use this tool.

Here you can download: http://pan.baidu.com/s/1i37kiVz

Finally, the specific commands for packaging are:


Of course, some programs cannot be repackaged back into the APK, for example, because it adds custom variables to the resources, which are defined in the plugin file, and the Apktool tool is naturally missing. Like the Widget.AppCompat.Base below.

[Email protected]:/tmp$ apktool B weixin/tmp.apki:checking Whether sources has changed ... I:checking whether resources has changed ... I:building Resources.../tmp/weixin/res/values/styles.xml:59:error:error Retrieving parent for item:no resource found T Hat matches the given name ' Widget.AppCompat.Base './tmp/weixin/res/values/styles.xml:275:error:error Retrieving Parent for Item:no Resource found that matches the given name ' Widget.AppCompat.Base './tmp/weixin/res/values/styles.xml: 467:error:error Retrieving parent for item:no Resource found that matches the given name ' Theme.AppCompat.Base '.

Second trick----view layout

Android also provides another very powerful tool hierarchyviewer, the principle of this tool I have in the screen free article has probably described, interested can go to see that article. This tool can be found in Android-sdk/tools. What the hell is this tool for? It is used to view the program's UI, using the following procedure:

1) After the command is started, the software will list all running programs


2) Select the program you are interested in, double click to view the program's UI, each box represents a view, and each box shows the view

ID, so that you can find out the view in Layoutxx.xml based on the ID well.


3) then select a view and double-click to see the view's UI.


4) Click on the layout on the right to see the layout information of the specific view, such as height, width, location, and other information.

With these two tools, you should be able to more convenient analysis of any program on the market interface structure.


Appendix:

above the Apktool, AAPT, it is best to copy these two files to the execution path, such as/usr/bin, so that Apktool can be found in the execution aapt this file. Also, all the tools in this article are under Linux, and if you want to perform under Windows, you can search for and download the Windows version. It should be noted that theHierarchyviewer tool is based on the ADB, to use it, you must ensure that the ADB devices can display to the Android device you want to access, the general Factory Equipment By default is not available, Root required.

/********************************

* This article from the blog "Love Kick Door"

* Reprint Please indicate the source : Http://blog.csdn.net/itleaks

******************************************/


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.