Android 4.1-compile the system browser into an Independent Application

Source: Internet
Author: User

To facilitate the debugging of the Android4.1 System Browser code on a mobile phone (Galaxy Note with CM10) and conduct code research, I compiled the system browser into an independent application, it will not conflict with the original system browser of ROM, so it is easy to track and debug the Java code in the project created by Eclipse, in theory, the C ++ part can also be debugged through GDB.


A self-compiled library that displays Layer boundaries and information

First, the system browser can be considered as divided into three parts:
1. Browser. Apk: a full-featured Browser Application
2. Some Java code of the android. webkit adaptation layer provides encapsulated WebView
3. libwebcore. so includes the WebKit code and the C ++ part of the platform adaptation layer, and the network stack of libchromium_net.so Chrome.

We actually only need the following two parts (2 and 3), and then add a simple test shell.
First refer to the official documentation, build a ROM compiling environment, compile ROM (http://source.android.com/source/index.html ).

Start to create an independent application (home/roger/a41 is the directory of my ROM and needs to be replaced with the directory of my ROM ):
Create an Android project in Eclipse and copy the Java code under the android. webkit directory;
Set EventLogTags under/home/roger/a41/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/webkit. java is also copied to its own project;
Because classes under android. webkit use non-public APIs in the SDK, we need to solve the compilation error:
Create a User Library and check the System Library option;
Add the following Jar package:
/Home/roger/a41/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes. jar
/Home/roger/a41/out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes. jar
/Home/roger/a41/out/target/common/obj/JAVA_LIBRARIES/bouncycastle_intermediates/classes. jar
Place the created Library at the beginning in Java Build Path/Order and Export;
Because the name of the android. webkit package in our application is the same as that in the SDK, we need to change the package name to android. webkit2;
We need to re-compile libchromium_net.so and libwebcore. so, use another name, and change the android/webkit/JNI path used in the code to android/webkit2/to ensure the correctness of JNI:
Under/home/roger/a41/external/chromium, change the android/webkit/path of all source files to android/webkit2 /;
Open/home/roger/a41/external/chromium/Android. mk, change the database name to libchromium_net2, and add a line of "LOCAL_MODULE_TAGS: = optional". For details, see;
Recompile chromium_net to obtain libchromium_net2.so;
Under/home/roger/a41/external/webkit/Source/WebKit/android, change the android/webkit/path of all Source files to android/webkit2 /;
Open/home/roger/a41/external/webkit/Android. mk: Change the database name to libwebcore2.so, and add a line of "LOCAL_MODULE_TAGS: = optional" (you need to modify the static library compilation and dynamic library compilation ), in addition, you also need to change the imported library libchromium_net to libchromium_net2. For details, refer to later;
Recompile webcore to obtain libwebcore2.so;
Next, we can push the modified libwebcore2.so and libchromium_net2.so to the rom of the mobile phone, assuming the path is/data/local (if there is no write permission, use Root Explorer to modify it );
Then we need to modify the Java code and let it load our own library. The modified location is in JniUtil. java and WebViewCore. java. For details, see (the loading sequence needs to be changed. First load libchromium_net2.so and then load libwebcore2.so );
Finally, add our own Test Shell code and run it. If only the C ++ code is modified, re-compile the code and then Push it to the mobile phone, then re-run Test Shell to take effect immediately. Java code can be easily debugged in Eclipse, and C ++ code can also be debugged through GDB theoretically;
LOCAL_MODULE: = libchromium_net2
LOCAL_MODULE_CLASS: = SHARED_LIBRARIES
LOCAL_MODULE_TAGS: = optional
INTERMEDIATES: = $ (call local-intermediates-dir)
# Define our module and find the intermediates directory
LOCAL_MODULE: = libwebcore2
LOCAL_MODULE_CLASS: = STATIC_LIBRARIES
LOCAL_MODULE_TAGS: = optional
Base_intermediates: = $ (call local-intermediates-dir)
# Do not attempt prelink this library. Needed to keep master-gpl happy, no
# Effect in master.
# TODO: remove this when master-gpl is updated.
LOCAL_PRELINK_MODULE: = false
LOCAL_MODULE: = libwebcore2
LOCAL_MODULE_TAGS: = optional
LOCAL_LDLIBS: = $ (WEBKIT_LDLIBS)
# Build the list of shared libraries
# We have to use the android version of libdl
LOCAL_SHARED_LIBRARIES: = \
LibEGL \
LibGLESv2 \
Libandroid \
Libandroidfw \
Libandroid_runtime \
Libchromium_net2 \
Libcrypto \
Libcutils \
Libdl \
Libgui \
Libicuuc \
Libicui18n \
Libmedia \
Libmedia_native \
Libnativehelper \
Libskia \
Libsqlite \
Libssl \
Libstlport \
Libutils \
Libui \
Libz
Static {
System. load ("/data/local/libchromium_net2.so ");
System. load ("/data/local/libwebcore2.so ");
}

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.