embed crosswalk in android studio
Asked Answered
S

5

9

I'm new about android programming and android studio. I researched crosswalk embed API for my project and tried to embed it in android studio. But I couldn't be succesfull. Even I don't know exactly how can embed an API that has gradle file or not.

Maybe there is a problem with gradle system? In brief, how can I embed crosswalk-webview to my project with android studio step by step? Thanks a lot you.

Suggs answered 28/2, 2015 at 12:39 Comment(0)
H
30

Following: https://diego.org/2015/01/07/embedding-crosswalk-in-android-studio/

  1. Open AndroidStudio to project view in app folder edit build.gradle:

    repositories {
    maven {
    url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'}}
    
    
    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'org.xwalk:xwalk_core_library:10.39.235.15'}
    
  2. sync project.

  3. add this view in layout xml.

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

    import org.xwalk.core.XWalkPreferences;
    import org.xwalk.core.XWalkView;
    
  5. in onCreate:

    XWalkView xWalkWebView=(XWalkView)findViewById(R.id.xwalkWebView);
    xWalkWebView.clearCache(true);
    xWalkWebView.load("http://...", null);
    // turn on debugging
    XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);
    

I've successfully used WebRTC in XWalkView on android 4.3 and 4.4 after failing with the out of the box WebView. I think the android 5 Lollipop is up to par with latest chromium.

Hesiod answered 9/3, 2015 at 8:36 Comment(8)
I needed to add <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> in the manifest file. Otherwise, my app was crashing.Armenia
dont know. you can use newer android and avoid all togetherHesiod
UPDATE: nvm, I didn't add repositories line to top level gradle file. Once I did that it seems to work. OLD: I just tried this and I'm getting Error:Failed to resolve: org.xwalk:xwalk_core_library:10.39.235.15. Anyone else seeing this? Have they removed the maven repo?Peachey
What do you mean by avoiding all together? @RubberDuckInapt
I'm sorry I don't recall the specifics.Hesiod
I think that web views in the newer Android SDKs support everything that crosswalk doe's out of the box e.g. Gogol's VoIP which exact name I don't recallHesiod
I'd like to have a WebView that loads/renders at the lowest priority and doesn't interfere that much with a GLSurfaceView running a game, is crosswalk capable of that?Dastardly
@ rraallvv sorry it's been a long time i'm not versedHesiod
V
2

To embed into new projects or to build with Android Studio 3, you have to change the following four files

This is a sample app.gradle file

apply plugin: 'com.android.application'
android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "online.saai.crosswalkandroid3"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-v4:27.1.0'
    }
}

dependencies {
    compile 'org.xwalk:xwalk_core_library:23.53.589.4'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

Things to consider,

  • To use the latest crosswalk 23.53.589.4 the min sdk version should be >= 16 here I used 17, ie minSdkVersion 17
  • maven repository repositories { ... } and compile dependency compile 'org.xwalk:xwalk_core_library:23.53.589.4' should be given to download latest crosswalk
  • Note You have to force gradle to use old android support library since there is a incompatibility in version 28 configurations.all { ... }

Once this is done replace your .xml file (activity_main.xml) with the following content, so that it can use crosswalk view

<?xml version="1.0" encoding="utf-8"?>
<org.xwalk.core.XWalkView android:id="@+id/activity_main"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
</org.xwalk.core.XWalkView>

Now MainActivity.java

public class MainActivity extends Activity {
  private XWalkView mXWalkView;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mXWalkView = (XWalkView) findViewById(R.id.activity_main);
    mXWalkView.load("http://crosswalk-project.org/", null);
  }
}

Finally allow your application to use internet and other permissions that you need in your application, got to `AndroidManifest.xml' and add this permissions. Here is a sample

<manifest ... />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    ...
<application ... />
Vitrification answered 25/3, 2018 at 17:4 Comment(1)
Do you know how to upgrade it to 64bit version?Libyan
L
0

Thanks for this Rubber Duck - it really helped me!

Note: if you're adding crosswalk to do webRTC, you need to add these to your manifest or the outgoing video/audio will not work (maybe you don't need them all, but it works for me!);

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

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

<uses-feature
    android:name="android.hardware.camera"
    android:required="true" />
Lemur answered 26/11, 2015 at 3:41 Comment(0)
E
0

Here is another tutorial on how to get Crosswalk into Android Studio, using this method you can select which processor architecture you want to target, thus reducing the APK file size to around 20 mb instead of the around 40 mb you end up with using the above method.

http://www.zhuatang.com/en/as-tips-3.jsp

When you create the resource folder in the tutorial be sure to use: File->New->Folder->Res Folder

At the end of the tutorial there is also a Github link to a functioning project created with the method described in the tutorial: https://github.com/zhsoft88/TestCrosswalkEmbed2

Engender answered 7/6, 2016 at 23:51 Comment(1)
not working this tips, still asking to extends XWalkActivity =(Loyceloyd
S
-1

This is needed as well to load images via html5, as hinted here

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (mXwalkView != null) {
        mXwalkView.onActivityResult(requestCode, resultCode, data);
    }
}
Sexennial answered 26/12, 2015 at 17:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.