CordovaWebView错误:org.apache.cordova.CordovaWebView无法转换为android.view.View。

5
我在Android上使用Cordova 5.1.1时遇到了一些问题。我正在尝试在我的应用程序中嵌入CordovaWebView。我已经按照官方site的所有说明进行操作,但是我一直收到错误信息“org.apache.cordova.CordovaWebView不能转换为android.view.View”。我搜索了很多帮助,但是找不到任何有用的信息。以下是我的代码:
活动:
public class CordovaTestActivity extends Activity implements CordovaInterface {

protected CordovaPlugin activityResultCallback = null;
protected boolean activityResultKeepRunning;
protected boolean keepRunning = true;
private final ExecutorService threadPool = Executors.newCachedThreadPool();
CordovaWebView cwv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cordova_test);
    cwv = (CordovaWebView) findViewById(R.id.tutorialView);
    Config.init(this);
    cwv.loadUrl(Config.getStartUrl());
}

@Override
public Activity getActivity() {
    return this;
}

@Override
public ExecutorService getThreadPool() {
    return threadPool;
}

@Override
public Object onMessage(String arg0, Object arg1) {
    return null;
}

@Override
public void setActivityResultCallback(CordovaPlugin plugin) {
    this.activityResultCallback = plugin;
}

@Override
public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode) {
     this.activityResultCallback = command;
     this.activityResultKeepRunning = this.keepRunning;

     if (command != null) {
         this.keepRunning = false;
     }

     super.startActivityForResult(intent, requestCode);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
     super.onActivityResult(requestCode, resultCode, intent);
     CordovaPlugin callback = this.activityResultCallback;
     if (callback != null) {
         callback.onActivityResult(requestCode, resultCode, intent);
     }
} }

xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.cordovatest.CordovaTestActivity" >

<org.apache.cordova.CordovaWebView
 android:id="@+id/tutorialView"
 android:layout_width="match_parent"
 android:layout_height="match_parent" />

</RelativeLayout>

config.xml

<widget id="com.example.hello" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<preference name="loglevel" value="DEBUG" />
<preference name="AndroidLaunchMode" value="singleTop" />
<name>Hello World</name>
<description>
    A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
    Apache Cordova Team
</author>
<content src="index.html" />
<access origin="*" />
<preference name="useBrowserHistory" value="true" />
<preference name="exit-on-suspend" value="false" />
<preference name="fullscreen" value="false" />
<preference name="webviewbounce" value="true" />
</widget>

1
看起来 Cordova 的开发人员已经将 org.apache.cordova.CordovaWebView 类转换为接口,但没有更新文档。如果您找到了任何修复方法,请告诉我,我很感兴趣。 - Brill Pappin
@BrillPappin 在这个相关问题下列出了一个可能的解决方案。然而,我还没有成功地让它正常工作。 - OJ7
@OJK - 谢谢,这个问题已经解决了,我不再需要处理 Cordova 了,但我相信这个链接对其他人会有所帮助。 - Brill Pappin
2个回答

1
我已经找到了解决方案。我们可以使用org.apache.cordova.engine.SystemWebView代替CordovaWebView,它将按预期工作。

1
我知道我回答这个问题已经太晚了,但今天我遇到了这个问题并尝试找到解决方案。
在Android的5.1.1版本中,Cordova实现中的CordovaWebView从CustomwebView转换为接口,我们不能在布局中使用它,这就是应用程序无法编译的原因。
另一个由Cordova提供的webview实现称为SystemWebView,位于org.apache.cordova.engine包下。
我不知道为什么Cordova开发人员将CordovaWebView转换为接口。

1
因为Cordova Android 4包含了“可插入Web视图”,而这种变化是必要的。 我不确定这是一个答案还是只是一个评论。 - jcesarmobile

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接