Android build failing with cordova plugins

We are using cordova plugins for facebook and push notifications. We can build for android (ionic build android) without those two plugins, but as soon as they are referenced in either package.json or config.xml we get the following error:

TypeError: Can’t call method on undefined

When we build for ios (ionic build ios), everything works fine. We are using the ionic-cli@beta.30.

package.json
"cordovaPlugins": [ "cordova-plugin-camera", "cordova-plugin-console", "ionic-plugin-keyboard", "cordova-plugin-x-socialsharing", "cordova-plugin-whitelist", "cordova-plugin-geolocation", { "variables": { "SENDER_ID": "123456789" }, "locator": "phonegap-plugin-push", "id": "phonegap-plugin-push" }, { "variables": { "APP_ID": "1608711046118075", "APP_NAME": "OurApp" }, "locator": "cordova-plugin-facebook4", "id": "cordova-plugin-facebook4" }, "cordova-plugin-contacts" ],

The corresponding config.xml:
<plugin name="cordova-plugin-geolocation" spec="~2.2.0"/> <plugin name="phonegap-plugin-push" spec="~1.6.4"> <variable name="SENDER_ID" value="123456789"/> </plugin> <plugin name="cordova-plugin-facebook4" spec="~1.7.1"> <variable name="APP_ID" value="1823894389234534298237234324"/> <variable name="APP_NAME" value="OurApp"/> </plugin>

Here the full stacktrace:

Caught exception:
TypeError: Can’t call method on undefined
at TypeError (native)
at module.exports (/Users/pivotal/workspace/gnome-app/ionic-app/node_modules/core-js/modules/_defined.js:3:28)
at createHTML (/Users/pivotal/workspace/gnome-app/ionic-app/node_modules/core-js/modules/_string-html.js:7:19)
at bold (/Users/pivotal/workspace/gnome-app/ionic-app/node_modules/core-js/modules/es6.string.bold.js:5:12)
at cb (/usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/node_modules/winston/lib/winston/logger.js:206:7)
at done (/usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/node_modules/winston/node_modules/async/lib/async.js:167:19)
at /usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/node_modules/winston/node_modules/async/lib/async.js:40:16
at /usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/node_modules/winston/lib/winston/logger.js:193:9
at Console.log (/usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/node_modules/winston/lib/winston/transports/console.js:127:3)
at emit (/usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/node_modules/winston/lib/winston/logger.js:186:17)
at /usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/node_modules/winston/node_modules/async/lib/async.js:157:13
at _each (/usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/node_modules/winston/node_modules/async/lib/async.js:57:9)
at Object.async.each (/usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/node_modules/winston/node_modules/async/lib/async.js:156:9)
at Logger.log (/usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/node_modules/winston/lib/winston/logger.js:214:9)
at target.(anonymous function) [as error] (/usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/node_modules/winston/lib/winston/common.js:54:18)
at Socket. (/usr/local/lib/node_modules/ionic/lib/utils/cordova.js:83:11)

Mind letting us know? https://github.com/driftyco/ionic-cli/issues

Any ideas how our package.json / config.xml breaks the android build? Any pointers are appreciated.

Having the exact same error. Did you figure out solutions on this?

No.

(forum wants me to use 20 characters at least, this is why you see this)

Ok, this is what I tried: I am experiencing this on a remote cloud build as well where Java and Droid PATH variables etc are all set perfectly. I tried with SDK and dependencies v23 as well as v24. I tried with ionic run into a Genymotion vBox but all without success resulting in the same error. I tried with cordova plugins commented out in config.xml. Tonight I will deinstall all cordova plugins and try again. Letting run with cordova -v instead of ionic emulate yielfs more debug issues. Keepnus posted about any progress, business impact on my side it quite huge.

Sorry, I forgot to mention that whilst we did not solve the issue, we found out that one of the plugins caused this shitshow. By commenting out the facebook plugin, we were able to build for android. We did not find out why this is happening. I hear you - it is super frustrating I must say, our team also spent about a day trying to fix it but things get really hard to trace back. Also, it somewhat defies the point of Ionic.

Hello! I have the same issue. Do you have any progress?

cordova plugin add cordova-plugin-facebook4 Caught exception: undefined

Sorting out the Android SDK and Build Versions as I described here http://meshfields.de/build-android-apk-with-ionic2-beta-and-cordova-on-a-osx/ solved problems.