Study Android development on the shoulders of giants

Source: Internet
Author: User

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


First move ---- Reverse Engineering

To analyze the software of giants, we naturally have to go through reverse engineering, which converts the APK program into the source code that we can see. This google official tool has helped us to do well. apktool is a good reverse tool.

For: http://pan.baidu.com/s/1kTqRhaR

The following uses an analysis as an example to describe how to use this tool:

You only need to execute the following command to complete reverse assembly. After completion, the tool generates the weixin directory.

apktool decode weixin.apk

In the directory, You can see various software resource files, including layout files. With these resource files, it is easy to make the same interface as yourself. Of course, the focus of the program is the code logic, not the interface.

itleaks@ITLeaks:/tmp$ ls weixin/AndroidManifest.xml  apktool.yml  assets  lib  res  smaliitleaks@ITLeaks $ ls weixin/res/ -a.                     layout       values-id       values-th..                    layout-hdpi  values-in       values-tranim                  layout-ldpi  values-it       values-v11color                 layout-mdpi  values-iw       values-v14drawable              layout-v11   values-ja       values-vidrawable-480dpi       raw          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-land         values-en    values-mdpi     values-w720dpdrawable-land-hdpi    values-es    values-ms       values-xhdpidrawable-mdpi         values-fr    values-pl       values-xlargedrawable-xhdpi        values-hdpi  values-pt       values-zh-rCNdrawable-zh-rCN-hdpi  values-he    values-ru       values-zh-rTWdrawable-zh-rTW-hdpi  values-hi    values-sw600dp  xml

The above is a smali Directory, which is the source code directory, and this source code smali is an intermediate language. It is neither a java language nor a java assembly language, it is a special language that can be recognized by apktool. To further convert it into a java language, we can use dex2jar and jd-gui tools.

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

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

The command is as follows:

Mv weixin.apk weixin.zip unzip-o weixin.zip // decompress the package to obtain the classes. dex file dex2jarRootPath/dex2jar. sh classes. dex // and then obtain the classes_dex2jar.jar file jd-gui plugin.

At the same time, you can modify the smali file and then use apktool to generate an apk again. You must download another aapt tool before using this command. apktool will use this tool.

You can download here: http://pan.baidu.com/s/1i37kiVz

Finally, the specific command for packaging is:

itleaks@ITLeaks:/tmp$ apktool b Filer/ tmp.apkI: Checking whether sources has changed...I: Checking whether resources has changed...I: Building apk file...itleaks@ITLeaks:/tmp$ 

Of course, some programs cannot re-package the apk, for example, because it adds custom variables in resources, which are defined in the plugin file, the apktool cannot be found. For example, the following Widget. AppCompat. Base

itleaks@ITLeaks:/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 that 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'.

Step 2 ---- view the view Layout

Android also provides another powerful tool, hierarchyviewer. The principle of this tool has been roughly described in the free articles on the screen. If you are interested, you can refer to the article. This tool can be found in android-sdk/tools. What is the use of this tool? It is used to view the UI of the program. The procedure is as follows:

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


2) Select the program you are interested in and double-click it to view the UI of the program. Each box on the interface represents a view, and the view is displayed under each box.

In this way, you can find the view corresponding to the view in layoutxx. xml according to the id.


3) Select a view and double-click it to view its UI.


4) Click layout on the right side to view the layout information of a specific view, such as the height, width, and position.

With these two tools, you can easily analyze the interface structure of any program on the market.


Appendix:

For the above apktool and aapt, we 'd better copy these two files to the execution path, such as/usr/bin, so that apktool can find the aapt file during execution. Also, all the tools in this article are in linux. If you want to execute them in Windows, you can search for and download the Windows version. It should be noted that the hierarchyviewer tool is based on adb. to use it, you must ensure that adb devices can display the Android devices you want to access. Generally, factory devices cannot be used by default, root is required.

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

* This article is from the blog "love to kick the door"

* Reprinted please indicate the source: http://blog.csdn.net/itleaks

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


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.