embed crosswalk in android studio

前端 未结 5 1504
有刺的猬
有刺的猬 2020-12-01 07:12

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

5条回答
  •  北海茫月
    2020-12-01 07:54

    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

    
    
    
    

    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

    
        
        
        
        ...
    
    

提交回复
热议问题