Android的NDK:自定义的WebView从源代码编译自定义、源代码、Android、NDK

2023-09-03 21:12:38 作者:我的爱已过期

我的目标是创造的WebView的(称之为WebViewCustom)修改后的版本在Android中为我在我的应用个人使用。的WebView是基于WebKit的,所以我需要通过NDK来编译在C。我在参与开源的Andr​​oid项目现在不感兴趣,所以我需要的是只是为了能够编译的WebView的原来的C源代码,并把它作为一个自定义的控制在我的Andr​​oid应用程序(SDK和NDK是可能的环境为应用程序)。我认为这是可能没有所有的GIT WebKit的东西我不感兴趣,但我不是机器人和WebKit项目的专家。是否有可能只是编辑和编译的WebView code,并把它在我的应用程序作为新的控制?你能告诉我这个任务的主要步骤?

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?

推荐答案

这当然是可能的。在从源代码重建 android.webkit 的主要困难在于缺乏正确的编译环境。这是从来没有打算要在目标平台的建外,但夫妇周围的来源简单的​​黑客使它很容易完成的任务。

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.

首先,整个 android.webkit 封装业务已被重新命名,原因很明显,因为一个 android.webkit.WebView 类在运行时应该已经可用。使用 SED 上的所有框架/基/核心/爪哇/安卓/ WebKit的树的例子。

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.

基本上,你要在这里http://source.android.com/source/initializing.html), 使框架来使内部运行环境可用,创建一个新的发展平台,从 framework.jar 更换所有类(建成后它在输出/目标/普通/ OBJ / JAVA_LIBRARIES / framework_intermediaries / classes.jar )到的android.jar ,建立自己的的WebKit 包反对这种包含内部新的平台。

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.

查看https://devmaze.word$p$pss.com/2011/01/18/using-com-android-internal-part-1-introduction/有关获取可用于发展目的的内部运行的详细信息。

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.

您还需要 core_intermediaries bouncycastle_intermediaries 等人为了编译的WebKit ,这些都是可用的,当使框架被调用,建立你的的WebKit 包和grep的输出/目标/普通/ OBJ / JAVA_LIBRARIES / 来找出哪些类包含的符号。

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.

这还不是全部,但是,包使用 libwebcore.so 它公开本地方法的 android.webkit 包;这将必须有注册到新包名称的所有本地方法绑定(在外部/ WebKit的/ WebKit的/安卓/ JNI ),并重新编译的没有prelinking 的(使libwebcore ),并打包您的应用程序作为本机库。

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.

一切都满足后,你会就要使用自己的的WebView 类从你自己的包,而不是 android.webkit 之一。如果您要更换 android.webview 完全 - 你将不得不重新编译 framework.jar 和内更换系统/框架/ (需要root权限)。

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).