我正在尝试使用 Phonegap 创建一个 Hello World 应用程序,但是当我调用在模拟器上运行该应用程序时它崩溃了。我遵循了指南 here .这是我在 MainActivity.java 上的内容:
package com.example.hello;
import android.os.Bundle;
import org.apache.cordova.*;
public class HelloWorld extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
// Set by <content src="index.html" /> in config.xml
super.loadUrl(Config.getStartUrl());
//super.loadUrl("file:///android_asset/www/index.html");
}
}
这是我的 AndroidManifest.xml :
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" android:windowSoftInputMode="adjustPan" package="com.example.hello" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:launchMode="singleTop" android:name="HelloWorld" android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="20" />
</manifest>
这是我得到的第一个错误:
- Chromium WebView 不存在
- 致命异常:main
- java.lang.RuntimeException: 无法启动 Activity ComponentInfo{com.example.deneme/com.example.deneme.MainActivity}: java.lang.UnsupportedOperationException
你能告诉我这个应用程序有什么问题吗?谢谢。
最佳答案
实际上,并非每部 Android 手机都附带 Chromium 作为 WebView 引擎(https://developer.chrome.com/multidevice/webview/overview)。例如,我的 Samsung Galaxy Ace2 和 Android 4.1.2 有旧的 WebView 引擎。用户代理字符串表示一些未知的 Mozilla 版本,HTML5 应用程序的外观和行为与 Chrome 不同。但是,PhoneGap 应用程序不会在我的手机上引发错误。
我不知道你为什么会收到“Chromium WebView 不存在”错误,但由于你正处于起步阶段(因为你正在尝试使用 Phonegap 构建 Hello World 应用程序)我想要指向另一个选项。使用Crosswalk项目允许你不用在每个 android 设备上处理各种 WebView 引擎,而是使用嵌入在你的应用程序 chromium 引擎中——在每个 android 设备上总是一样的。 crosswalk 项目可用于 android 和 tizen 平台。因此,要构建跨平台应用程序(android 和 iOS),我建议使用其中之一
- Intel XDK ,它可以使用带有 XDK api 和 Cordova api 的单个 html5 源代码,可以使用 crosswalk 编译到 android 应用程序或使用 native WebView 编译到 iOS。
- Crosswalk+Cordova从相同的来源构建 Android 应用程序和 PhoneGap 构建 iOS 应用程序
这种方法可以消除支持各种 android 设备的痛苦。
另见:
http://html5hub.com/building-cordova-applications-with-crosswalk/
https://groups.google.com/forum/#!topic/phonegap/IxSuRUScbMs
关于java - Chromium WebView 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25019784/