Crosswalk - Inflating class & Cie

为君一笑 提交于 2019-12-22 01:03:40

问题


I'm currently working with Crosswalk ( previously on Cordova ). But I encounter a problem : when i'm creating just a simple XWalkView, nothing works..

I mean, I followed all guides, try multiples ways and nothing . I'm working with CrossWalk 12.41.296.9 ARM.

That way:

public class MainActivity extends Activity {
    private static final String url = "file:///android_asset/www/index.html";

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cordova_layout);
        XWalkView webView = (XWalkView) findViewById(R.id.cordova_webview);
        webView.load(url,null);

    }
}

With this "cordova_layout" :

<org.xwalk.core.XWalkView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/cordova_webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent">    
</org.xwalk.core.XWalkView>

Or even that way

public class MainActivity extends Activity {
    private static final String url = "file:///android_asset/www/index.html";

    @Override
    public void onCreate(Bundle savedInstanceState)   {
        super.onCreate(savedInstanceState);
        XWalkView cordovaWebView = new XWalkView(this.getApplicationContext(),this);
        cordovaWebView.load(url,null);
        setContentView(cordovaWebView);
    }
}

is giving my that inflating error

05-07 14:34:25.296  26681-26681/fr.ab.xwalkCordova E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: fr.ab.xwalkCordova, PID: 26681
java.lang.RuntimeException: Unable to start activity ComponentInfo{fr.ab.xwalkCordova/fr.ab.xwalkCordova.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class org.xwalk.core.XWalkView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2367)
        at android.app.ActivityThread.access$800(ActivityThread.java:148)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5274)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)

Here is my Manifest

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1"     android:versionName="0.0.1" package="fr.ab.xwalkCordova"     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-sdk android:minSdkVersion="17" android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.REORDER_TASKS" />
<uses-feature android:name="android.hardware.camera" />

<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true"
             android:allowBackup="true">
    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
        <intent-filter android:label="@string/launcher_name">
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>    

Please help :'(


回答1:


Replace this

    XWalkView cordovaWebView = new XWalkView(this.getApplicationContext(),this);
    cordovaWebView.load(url,null);
    setContentView(cordovaWebView);

with

    setContentView(R.layout.cordova_layout);
    XWalkView cordovaWebView = (XWalkView)findViewById(R.id.cordova_webview);
    cordovaWebView.load(url,null);

EDIT: Here is an example that worked for me:

public class MainActivity extends AppCompatActivity {
    private XWalkView xWalkWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().requestFeature(Window.FEATURE_PROGRESS);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN
        );
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        xWalkWebView = (XWalkView) findViewById(R.id.xwalkWebView);           
        xWalkWebView.load(url, null);

        // turn on debugging
        // XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);
    }

    @Override
    protected void onPause() {
        super.onPause();
        if(xWalkWebView != null) {
            xWalkWebView.pauseTimers();
            xWalkWebView.onHide();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if(xWalkWebView != null) {
            xWalkWebView.resumeTimers();
            xWalkWebView.onShow();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(xWalkWebView != null) {
            xWalkWebView.onDestroy();
        }
    }
}

Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="#000000">

    <org.xwalk.core.XWalkView
        android:id="@+id/xwalkWebView"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#000000"
        />

</LinearLayout>

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="my.xwalk.thing" >

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">

        <activity
            android:name=".MainActivity"
            android:screenOrientation="landscape"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Module-level gradle:

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "my.xwalk.thing"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        // Exclude file to avoid
        // Error: Duplicate files during packaging of APK
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'org.xwalk:xwalk_core_library_beta:11.40.277.6'
}

and project level gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'
        }
    }
}

Please update the outdated Android Gradle plugin, Support library, the Crosswalk version and the compile/buildtool/targetSDK.



来源:https://stackoverflow.com/questions/30101485/crosswalk-inflating-class-cie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!