如何将webview集成到aosp中?

时间:2019-01-16 09:57:28

标签: java android android-webview android-source

我已经为远足建立了自己的android操作系统,并将新的应用程序查看包添加到了packages文件夹中,并重建了系统,它可以全部成功编译。

刷卡后,启动Webview应用程序时会出现异常“ E WebViewFactory: Chromium WebView package does not exist

01-14 17:53:55.994  2380  3270 I ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.testapps.TestWebviewApp1 cmp=com.testapps.TestWebviewApp1/.MainActivity} from uid 10051
01-14 17:53:54.604  2148  2197 I chatty  : uid=1054(vehicle_network) android.hardwar identical 6 lines
01-14 17:53:55.604  2148  2197 E automotive.vehicle@2.0-impl: Discarding value for prop 0x11600703 because it contains data that is not consistent with this pool. Expected type: 6291456, vector size: 0
01-14 17:53:56.009  2146  3660 W StreamHAL: Error from HAL stream in function get_presentation_position: Operation not permitted
01-14 17:53:56.009  2146  3660 W StreamHAL: Error from HAL stream in function get_presentation_position: Operation not permitted
01-14 17:53:56.015  3959  3959 I Zygote  : seccomp disabled by setenforce 0
01-14 17:53:56.015  2380  3270 I ActivityManager: Start proc 3959:com.testapps.TestWebviewApp1/u0a2 for activity com.testapps.TestWebviewApp1/.MainActivity
01-14 17:53:57.235  2380  3270 W WebViewUpdater: creating relro file timed out
01-14 17:53:57.238  3959  3959 E WebViewFactory: Chromium WebView package does not exist
01-14 17:53:57.238  3959  3959 E WebViewFactory: android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.webkit.WebViewFactory.getWebViewContextAndSetProvider(WebViewFactory.java:320)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:383)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:194)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.webkit.WebView.getFactory(WebView.java:2531)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.webkit.WebView.ensureProviderCreated(WebView.java:2526)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.webkit.WebView.setOverScrollMode(WebView.java:2591)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.view.View.<init>(View.java:4574)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.view.View.<init>(View.java:4706)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.view.ViewGroup.<init>(ViewGroup.java:597)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.webkit.WebView.<init>(WebView.java:643)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.webkit.WebView.<init>(WebView.java:588)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.webkit.WebView.<init>(WebView.java:571)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.webkit.WebView.<init>(WebView.java:558)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at java.lang.reflect.Constructor.newInstance0(Native Method)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.view.LayoutInflater.createView(LayoutInflater.java:647)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:419)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.app.Activity.setContentView(Activity.java:2685)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at com.testapps.TestWebviewApp1.MainActivity.onCreate(MainActivity.java:16)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.app.Activity.performCreate(Activity.java:7015)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.app.Activity.performCreate(Activity.java:7006)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2735)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2860)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.app.ActivityThread.access$1300(ActivityThread.java:176)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1591)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.os.Handler.dispatchMessage(Handler.java:106)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.os.Looper.loop(Looper.java:164)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at android.app.ActivityThread.main(ActivityThread.java:6518)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at java.lang.reflect.Method.invoke(Native Method)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
01-14 17:53:57.238  3959  3959 E WebViewFactory:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:853)
01-14 17:53:57.239  3959  3959 D AndroidRuntime: Shutting down VM
01-14 17:53:57.240  3959  3959 E AndroidRuntime: FATAL EXCEPTION: main
01-14 17:53:57.240  3959  3959 E AndroidRuntime: Process: com.testapps.TestWebviewApp1, PID: 3959
01-14 17:53:57.240  3959  3959 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testapps.TestWebviewApp1/com.testapps.TestWebviewApp1.MainActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class android.webkit.WebView
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2784)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2860)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.app.ActivityThread.access$1300(ActivityThread.java:176)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1591)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:106)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:164)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:6518)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:853)
01-14 17:53:57.240  3959  3959 E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class android.webkit.WebView
01-14 17:53:57.240  3959  3959 E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class android.webkit.WebView
01-14 17:53:57.240  3959  3959 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at java.lang.reflect.Constructor.newInstance0(Native Method)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.view.LayoutInflater.createView(LayoutInflater.java:647)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:419)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.app.Activity.setContentView(Activity.java:2685)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at com.testapps.TestWebviewApp1.MainActivity.onCreate(MainActivity.java:16)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.app.Activity.performCreate(Activity.java:7015)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.app.Activity.performCreate(Activity.java:7006)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2735)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2860)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.app.ActivityThread.access$1300(ActivityThread.java:176)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1591)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:106)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:164)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:6518)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:853)
01-14 17:53:57.240  3959  3959 E AndroidRuntime: Caused by: android.util.AndroidRuntimeException: android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:423)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:194)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.webkit.WebView.getFactory(WebView.java:2531)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.webkit.WebView.ensureProviderCreated(WebView.java:2526)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.webkit.WebView.setOverScrollMode(WebView.java:2591)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.view.View.<init>(View.java:4574)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.view.View.<init>(View.java:4706)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.view.ViewGroup.<init>(ViewGroup.java:597)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.webkit.WebView.<init>(WebView.java:643)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.webkit.WebView.<init>(WebView.java:588)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.webkit.WebView.<init>(WebView.java:571)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.webkit.WebView.<init>(WebView.java:558)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    ... 28 more
01-14 17:53:57.240  3959  3959 E AndroidRuntime: Caused by: android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.webkit.WebViewFactory.getWebViewContextAndSetProvider(WebViewFactory.java:320)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:383)
01-14 17:53:57.240  3959  3959 E AndroidRuntime:    ... 40 more
01-14 17:53:57.245  2380  3270 W ActivityManager:   Force finishing activity com.testapps.TestWebviewApp1/.MainActivity
01-14 17:53:57.249  3959  3959 I Process : Sending signal. PID: 3959 SIG: 9
01-14 17:53:57.306  2380  3270 I ActivityManager: Process com.testapps.TestWebviewApp1 (pid 3959) has died: fore TOP 
01-14 17:53:57.306  2380  2397 W libprocessgroup: kill(-3959, 9) failed: No such process
01-14 17:53:57.308  2141  2141 I Zygote  : Process 3959 exited due to signal (9)
01-14 17:53:57.331  2380  3270 I WifiService: getWifiEnabledState uid=1000
01-14 17:53:57.350  2380  2397 W libprocessgroup: kill(-3959, 9) failed: No such process
01-14 17:53:57.350  2380  2397 I libprocessgroup: Successfully killed process cgroup uid 10002 pid 3959 in 43ms
01-14 17:53:57.365  3449  3509 D mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, egl_color_buffer_format *, EGLBoolean) returns 0x3000
01-14 17:53:57.383  3449  3509 D vndksupport: Loading /vendor/lib64/hw/gralloc.hikey960.so from current namespace instead of sphal namespace.
01-14 17:53:57.430  2155  2296 D vndksupport: Loading /vendor/lib64/hw/gralloc.hikey960.so from current namespace instead of sphal namespace.
01-14 17:53:57.604  2148  2197 E automotive.vehicle@2.0-impl: Discarding value for prop 0x11600703 because it contains data that is not consistent with this pool. Expected type: 6291456, vector size: 0
01-14 17:54:00.074  2380  2629 E TaskPersister: File error accessing recents directory (directory doesn't exist?).

为什么会有这个例外?你有解决办法吗?

注意:我在external文件夹中有一个chromium-webview,当我签入android的文件系统时,我发现:

adb shell
hikey960:/ $ find . -name  webview.apk 2> /dev/null                        
./system/app/webview/webview.apk

external / chromium-webview中Android.mk的内容:

#
# Copyright (C) 2014 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Install the prebuilt webview apk.

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := webview
LOCAL_MODULE_CLASS := APPS
LOCAL_MULTILIB := both
LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
LOCAL_REQUIRED_MODULES := \
        libwebviewchromium_loader \
        libwebviewchromium_plat_support

LOCAL_MODULE_TARGET_ARCH := arm arm64 x86 x86_64
my_src_arch := $(call get-prebuilt-src-arch,$(LOCAL_MODULE_TARGET_ARCH))
LOCAL_SRC_FILES := prebuilt/$(my_src_arch)/webview.apk

LOCAL_PREBUILT_JNI_LIBS_arm := @lib/armeabi-v7a/libwebviewchromium.so
LOCAL_PREBUILT_JNI_LIBS_arm64 := @lib/arm64-v8a/libwebviewchromium.so
LOCAL_PREBUILT_JNI_LIBS_x86 := @lib/x86/libwebviewchromium.so
LOCAL_PREBUILT_JNI_LIBS_x86_64 := @lib/x86_64/libwebviewchromium.so

include $(BUILD_PREBUILT)

1 个答案:

答案 0 :(得分:0)

我已通过如下更改配置文件config_webview_packages.xml来解决此问题:

<!--
 Copyright 2016 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<!-- WebView providers in order of preference -->
<!--
 Signature checks are ignored if the package is preinstalled or if this is a userdebug or eng
    build. If no signature is provided, the package can provide a WebView implementation only on userdebug/eng builds or if it's preinstalled 
-->
<webviewproviders>
<webviewprovider description="Chrome Stable" packageName="com.android.chrome" availableByDefault="true">
<!--
 Ignore this package on user/release builds unless preinstalled. 
-->
</webviewprovider>
<!-- The default WebView implementation -->
<webviewprovider description="Android WebView" packageName="com.android.webview" availableByDefault="true"> </webviewprovider>
</webviewproviders>