Skip to content

Instantly share code, notes, and snippets.

@shaxxx
Last active September 3, 2020 01:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save shaxxx/20bf4f85e2c66022e0ca74856811f5d7 to your computer and use it in GitHub Desktop.
Save shaxxx/20bf4f85e2c66022e0ca74856811f5d7 to your computer and use it in GitHub Desktop.
Crosswalk + Ionic4
//star blank Ionic project
ionic start walk sidemenu --type=angular
//change to Ionic project folder
cd walk
//add android platform
ionic cordova platform add android
//remove Ionic webview
ionic cordova plugin remove cordova-plugin-ionic-webview
//add crosswalk webview
ionic cordova plugin add cordova-plugin-crosswalk-webview
//add plugin to fix crosswalk build error due to gradle error
ionic cordova plugin add cordova-android-support-gradle-release
//modify src/index.html and change
<base href="/" />
//to
<base href="/android_asset/www/" />
//modify src/main.ts to fix "URL scheme "file" is not supported." when loading SVG assets
//https://github.com/ionic-team/ionicons/issues/572#issuecomment-402895894
//add
function androidFetchWorkaround() {
const originalFetch = (window as any).fetch;
(window as any).fetch = (...args) => {
const [url] = args;
if (typeof url === 'string' && url.match(/\.svg/)) {
return new Promise((resolve, reject) => {
const req = new XMLHttpRequest();
req.open('GET', url, true);
req.addEventListener('load', () => {
resolve({ ok: true, text: () => Promise.resolve(req.responseText) });
});
req.addEventListener('error', reject);
req.send();
});
} else {
return originalFetch(...args);
}
};
}
androidFetchWorkaround();
//above
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
//run on android
ionic cordova run android
@M-Abozaid
Copy link

M-Abozaid commented May 17, 2019

I'm getting
Failed to load resource: net::ERR_FILE_NOT_FOUND
with both <base href="/android_asset/www/" /> and <base href="/" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment