Androd plug-in Development Atlas Resource Packaging Tool patch AAPT compilation

Source: Internet
Author: User

Let's take a look at the contents of the auto-generated R file in Android studio, and you'll find that there are many internal classes in the R file, and there are many int types in the inner class, and they all start with 0x7f .

When we compile resources for an Android application, at least two packages are involved, one of which is the referenced system resource bundle, and the other is the application resource bundle that is currently being compiled. Each package can define its own resources, and it can also reference the resources of other packages. So, how does a package refer to the resources of other packages? This is the resource ID we are familiar with. The resource ID is a 4-byte unsigned integer in which the highest byte represents the package ID, the second high byte represents the Type ID, and the minimum two bytes represents the Entry ID.

The package ID is equivalent to a namespace that qualifies the source of the resource. The Android system currently defines two resource command spaces, one of which is a system resource command space, its package ID equals 0x01, and the other is the application Resource command space, which has a package ID equal to 0x7f. All package IDs located between [0x01, 0x7f] are legal, and outside of this range are illegal package IDs. The package ID of the system Resource pack package-export.apk mentioned earlier is equal to 0x01, and the value of the packages ID of the resource that we define in the application is equal to 0x7f, which can be verified by the generated R.java file.

The type ID refers to the resource's kind ID. There are several types of resources, animator, anim, color, drawable, Layout, menu, raw, String, and XML, each of which is given an ID.

Entry ID refers to the order in which each resource appears in the type of resource to which it belongs. Note that the entry IDs of different types of resources may be the same, but because of their different types, we can still differentiate them by their resource IDs.

For more details, you can learn more about the following two articles.
-Android Resource Management framework (Asset Manager) Brief introduction and Learning Plan
-Compilation and packaging process analysis for Android application resources

All Atlas plugins need to specify the resource partition in the Build.gradle file, which is the value between Versionname and [0x1, 0x7f], which is packaged using patch AAPT.

We can print out the package ID by patch AAPT, and we'll see that the package ID is the 0x21 we specified.

The Android resources in Atlas can be broadly divided into two parts, the system layer resources and the Application Layer resource system layer resources are divided into three parts (5.0 versions are divided into two parts)
    1. System framework layer, Android Core Framework layer resource ID is 0x01
    2. Shared resource layer, this part of the resource ID is 0x00, and the developer is not very related, we do not directly use this part
    3. WebView layer, Resource ID is 0x02. (This starts at Android 5.0) (googlewebview.apk)
The application layer is divided into two parts, the host layer and the component layer
    1. Component-level resources are independent from each other and are non-conflicting (ID distributions from 0x10 to 0x7e)
    2. The host layer's resources are still 0x7f, keeping the default values.
    3. Where the host layer contains shared resources (similar to system shared resources), the component layer may be dependent on the host tier's shared resources (Plan 1.0 support)

This picture is summarized as follows

To implement a partition of a resource, you must use a patched AAPT for resource packaging. Here we compile the patch aapt.

The compilation environment is Ubuntu 14.04, refer to http://source.android.com/source/initializing.html for environment configuration.

$ sudo apt-get update$ sudo apt-get install openjdk-7-jdk$ sudo apt-get install bison g++-multilib git gperf libxml2-utils make python-networkx zlib1g-dev:i386 zip

Temporary increase of environment variables

$ mkdir ~/bin$ PATH=~/bin:$PATH

Download Repo tool, this step need to turn over the wall, you can use hosts,hosts see http://laod.cn/hosts/2015-google-hosts.html

$ https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo$ chmod a+x ~/bin/repo

Git configuration

$ "[email protected]"$ "Your Name"

Source download, use the image of Tsinghua University

$ mkdir ~/Android$ repo init -u git://aosp.tuna.tsinghua.edu.cn/android/platform/manifest$ repo sync

The next step is waiting, waiting for the time to see your speed. 100M speed, probably also a few hours, almost a day, support for the continuation of the breakpoint

Configuring the Environment

$ Android$ . build/envsetup.sh

Enter the following directory when finished

cd Android/frameworks/base

Copy the Base.patch in the Openatlas to this directory. Before applying the patch, it is best to switch to the corresponding branch (presumably the branch of android5.1.1, which is unclear).

patch -p1 < base.patch

If nothing goes wrong, the application succeeds.

Compile AAPT, if you want to compile the version of Windows, note add use_mingw=1

$ USE_MINGW=1 make aapt

If it's just a Linux version, it's directly

$ make aapt

If there is no error, the compilation succeeds, and the corresponding file is

Android/out/host/windows-x86/bin

Or

Android/out/host/linux-x86/bin

Replace the original AAPT. But later found that the compiler completed AAPT compared to the AAPT to provide a lot more .... Unknown reason:

If you are prompted during the compilation process

‘size_t‘‘unsigned long‘and‘int‘[-Werror,-Wsign-compare]

Find the code in the corresponding file, cast to int after the comparison (I do not know whether there is an impact, the source is not carefully read), so it is best to switch to the corresponding branch and then apply patch

Replace the original AAPT, test, if the plug-in works, almost succeeded. Is the result of the printing, found that the package has been modified, the operation of the result map is not posted

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Androd plug-in Development Atlas Resource Packaging Tool patch AAPT compilation

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.