Last active
September 3, 2020 01:03
-
-
Save shaxxx/20bf4f85e2c66022e0ca74856811f5d7 to your computer and use it in GitHub Desktop.
Crosswalk + Ionic4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting
Failed to load resource: net::ERR_FILE_NOT_FOUND
with both
<base href="/android_asset/www/" /> and <base href="/" />