Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
420 views
in Technique[技术] by (71.8m points)

c - Android NDK: custom WebView compiling from source

My goal is to create a modified version of WebView (call it WebViewCustom) in Android for my personal use in my application. WebView is WebKit based so I need to compile it in C by means of NDK. I am not interested in participating in the open-source Android project now, so my need is just to be able to compile the original C source of WebView and use it as a customized control in my Android application (both SDK and NDK are possible environments for the application). I think it is possible without all that GIT WebKit stuff I am not interested in, but I am not an expert of the Android and WebKit projects. Is it possible to just edit and compile the WebView code and put it in my application as a new control? Can you show me the main steps of this task?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is certainly possible. The main difficulty in rebuilding android.webkit from source lies in the lack of a correct build environment. It was never intended to be built outside of the target platform, but a couple of simple hacks around the sources make it quite easy to accomplish.

First of all, the whole android.webkit package business has to be renamed for obvious reasons, since an android.webkit.WebView class would already be available during runtime. Use sed on all the frameworks/base/core/java/android/webkit tree for example.

Basically you have to grab the full source tree, initialize a build environment (More information here http://source.android.com/source/initializing.html), make framework to make the internal runtime environment available, create a new development platform, replace all the classes from framework.jar (after building it's in out/target/common/obj/JAVA_LIBRARIES/framework_intermediaries/classes.jar) into android.jar of the platform, build your own webkit package against this new platform that contains the internals.

Check out https://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-1-introduction/ for more information on getting an internal runtime available for development purposes.

You will also need core_intermediaries, bouncycastle_intermediaries and others in order to compile webkit, these are all available when make framework is invoked, look at the errors when building your webkit package and grep the out/target/common/obj/JAVA_LIBRARIES/ to figure out which classes contain the symbols.

That's not all, however, the package uses libwebcore.so which exposes native methods to the android.webkit package; this would have to have all native method bindings registered to your new package name (in external/webkit/WebKit/android/jni) and be recompiled without prelinking (make libwebcore) and packaged with your application as a native library.

After everything is satisfied, you would then use your own WebView class from your own package instead of the android.webkit one. If you intend to replace android.webview completely - you would have to recompile a framework.jar and replace it inside system/framework/ (root privileges required).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...