-
-
Save joeljeske/68121fa6d643e0937f50458d0172e16e to your computer and use it in GitHub Desktop.
/** | |
* This hook overrides a function check at runtime. Currently, cordova-android 7+ incorrectly detects that we are using | |
* an eclipse style project. This causes a lot of plugins to fail at install time due to paths actually being setup | |
* for an Android Studio project. Some plugins choose to install things into 'platforms/android/libs' which makes | |
* this original function assume it is an ecplise project. | |
*/ | |
module.exports = function(context) { | |
if (context.opts.cordova.platforms.indexOf('android') < 0) { | |
return; | |
} | |
const path = context.requireCordovaModule('path'); | |
const androidStudioPath = path.join(context.opts.projectRoot, 'platforms/android/cordova/lib/AndroidStudio'); | |
const androidStudio = context.requireCordovaModule(androidStudioPath); | |
androidStudio.isAndroidStudioProject = function() { return true; }; | |
}; |
Thanks for this fix! If you already have plugins installed (ie: already have ios platform working) you can add
<platform name="android">
<hook src="scripts/patch-android-studio-check.js" type="before_plugin_install" />
</platform>
So it will run before install plugins in new platform
just to let you know, cordova has a fix for it too.
add this to your config.xml:
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" />
source: http://cordova.apache.org/announcements/2017/12/04/cordova-android-7.0.0.html
just tested it and it works!
Thank you very much for the patch ! I did not succeed to apply "official" method with the edit-config tag.
Any details or advices @fishgrind please ?
As said here on stack overflow, we should add a few more hooks to let the projects build:
<hook src="hooks/patch-android-studio-check.js" type="before_plugin_install" />
<hook src="hooks/patch-android-studio-check.js" type="before_plugin_add" />
<hook src="hooks/patch-android-studio-check.js" type="before_build" />
<hook src="hooks/patch-android-studio-check.js" type="before_run" />
<hook src="hooks/patch-android-studio-check.js" type="before_plugin_rm" />
I was running the same issues on build/run too
Thank you! It works great in terms of the error 'ENOENT: no such file or directory'.
In my case, some plugins don't support newer Android codes. So my solution was to downgrade android platform to 6.3.0.
Doesn't work for me:
ionic versio: 3.20
npm: 5.6.0
node: v8.11.3
Tried both the hooks folder solution and the one suggested in http://cordova.apache.org/announcements/2017/12/04/cordova-android-7.0.0.html.
The whole trace of error:
cp: copyFileSync: could not write to dest file (code=ENOENT):/Users/jorge.banguera/projects/fp-kitchen-ioinic/platforms/android/res/xml/config.xml
Parsing /Users/jorge.banguera/projects/fp-kitchen-ioinic/platforms/android/res/xml/config.xml failed
(node:87312) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '/Users/jorge.banguera/projects/fp-kitchen-ioinic/platforms/android/res/xml/config.xml'
at Object.fs.openSync (fs.js:646:18)
at Object.fs.readFileSync (fs.js:551:33)
at Object.parseElementtreeSync (/Users/jorge.banguera/projects/fp-kitchen-ioinic/platforms/android/cordova/node_modules/cordova-common/src/util/xml-helpers.js:180:27)
at new ConfigParser (/Users/jorge.banguera/projects/fp-kitchen-ioinic/platforms/android/cordova/node_modules/cordova-common/src/ConfigParser/ConfigParser.js:30:24)
at updateConfigFilesFrom (/Users/jorge.banguera/projects/fp-kitchen-ioinic/platforms/android/cordova/lib/prepare.js:106:18)
at Api.module.exports.prepare (/Users/jorge.banguera/projects/fp-kitchen-ioinic/platforms/android/cordova/lib/prepare.js:42:20)
at Api.prepare (/Users/jorge.banguera/projects/fp-kitchen-ioinic/platforms/android/cordova/Api.js:192:45)
at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/prepare.js:106:36
at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:787:54)
at self.promiseDispatch.done (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:816:30)
(node:87312) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:87312) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
any ideas?
I finally made it work but I gad to downgrade the android platform version to 6.3.0
worked for me on [email protected], cheers!
FYsI: updating to Android 8.0.0, from 7.1.4, meant I had to remove this script as it was causing build errors.
I'm upgrading to 8.0.1 and still running into the same issue, unfortunately . Does anyone have any idea ?
Error: ENOENT: no such file or directory, open './platforms/android/AndroidManifest.xml'
Add this hook to your cordova project using the cordova hooks syntax. I've found success using only "before_plugin_add".