Android NDK:从源代码编译的自定义 WebView [英] Android NDK: custom WebView compiling from source

查看:15
本文介绍了Android NDK:从源代码编译的自定义 WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是在 Android 中创建 WebView 的修改版本(称为 WebViewCustom),供我个人在我的应用程序中使用.WebView 是基于 WebKit 的,所以我需要通过 NDK 在 C 中编译它.我现在对参与开源的Android项目没有兴趣,所以我的需要只是能够编译WebView的原始C源并将其用作我的Android应用程序中的自定义控件(SDK和NDK都是可能的环境)申请).我认为没有我不感兴趣的所有 GIT WebKit 东西是可能的,但我不是 Android 和 WebKit 项目的专家.是否可以只编辑和编译 WebView 代码并将其作为新控件放入我的应用程序中?你能告诉我这个任务的主要步骤吗?

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 的主要困难在于缺乏正确的构建环境.它从未打算在目标平台之外构建,但是围绕源代码进行了一些简单的 hack 使得它很容易实现.

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 类在运行时已经可用.例如,在所有 frameworks/base/core/java/android/webkit 树上使用 sed.

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), make framework 使内部运行环境可用,创建一个新的开发平台,替换 中的所有类framework.jar(在 out/target/common/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.wordpress.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_intermediariesbouncycastle_intermediaries等来编译webkit,这些都可以在make framework 被调用,在构建您的 webkit 包时查看错误,并 grep out/target/common/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 包;这必须将所有本机方法绑定注册到您的新包名称(在 external/webkit/WebKit/android/jni 中)并重新编译无需预链接(制作 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 并在 system/framework/ 中替换它(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).

这篇关于Android NDK:从源代码编译的自定义 WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆