androidaxioscocoscreator

I want to use axios with Android build of CocosCreator


I could use axios in the browser with Cocos Creator.
But in android build I got an error.
ERROR: Uncaught TypeError: Cannot read property 'charAt' of undefined, location: assets/main/index.c8cc9.js:0:0

Made this change.

pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
urlParsingNode.pathname :
'/' + urlParsingNode.pathname

pathname:urlParsingNode.pathname

However, no response is returned.
Only Mock returns a response.

Need to change axios source code?


Solution

  • you can try add this code block

    if (cc.sys.isNative 
        && typeof navigator !== 'undefined' 
        && typeof navigator.product !== 'undefined') {
        Object.defineProperty(navigator, "product", {value: "NativeScript"});
    }