29

I have an ionic/cordova project using:

cordova-android@6.2.0
cordova-plugin-crosswalk-webview@2.3.0
cordova cli 6.4.0
ionic 1.3.3

When I try to add the Android platform, I get the following output

================

$ ionic platform add android@6.2.0

Adding android project...


Creating Cordova project for the Android platform:

    Path: platforms/android
    Package: com.ionicframework.name
    Name: name
    Activity: MainActivity
    Android target: android-25

Subproject Path: CordovaLib

Android project created with cordova-android@6.2.0

Error: cordovaProject.projectConfig.getFileResources is not a function

Devid Farinelli
  • 7,514
  • 9
  • 42
  • 73
JackDev
  • 4,891
  • 1
  • 39
  • 48
  • Couldn't reproduce this bug, could you please provide minimal sample where this bug reproduces? How do you run your app, is there stack trace with this error? – Bob Apr 04 '17 at 11:29
  • Hi @Bob, I have updated my question to show the the feedback I get, since it seems it already happens when adding the platform. There is no other feedback, and running the command with --stacktrace does not produce any additional logs. – JackDev Apr 04 '17 at 14:39
  • I have the same problem any ideas ? – solimanware Apr 04 '17 at 19:37
  • @Microsmsm - just use 6.1.2 for now? – JackDev Apr 04 '17 at 21:45
  • The new solution is to use 6.2.1, which seems to fix the issue. – JackDev Apr 06 '17 at 14:58

6 Answers6

44

It seems this issue is related to a bug in cordova-android@6.2.0, as confirmed here: https://issues.apache.org/jira/browse/CB-12633

I have now updated my system to cordova-cli - cordova@6.5.0 and cordova-android@6.2.1, and it seemed to work.

Update to version 6 of cordova cli with:

npm install -g cordova@6

And then add the correct version of cordova-android

cordova platform add android@6

Not directly related to this issue, but once I got it working, my system did complain about the gradle path not being set when I tried building my app, and so I followed the steps here: https://gradle.org/install#with-homebrew, and now all builds successfully.

JackDev
  • 4,891
  • 1
  • 39
  • 48
  • @Microsmsm - I believe 6.2.0 is the latest as of right now, although I see a 6.2.1 but looks like it has not yet been released completely. The previous version 6.1.2 does still seem to work though. If you run ionic platform rm android && ionic platform add android@6.1.2, it should work for the moment. – JackDev Apr 04 '17 at 21:41
  • 6.2.1 has been released now – jcesarmobile Apr 06 '17 at 14:10
  • 3
    I have 6.3.0 and still the same issue – holographix Apr 06 '17 at 14:26
  • @holographix - As I understand it the latest cordova-android version is 6.2.1, perhaps you are referring to your version of the cordova-cli? I am going to test this in a minute to check if it is working now. Try running $ cordova platform to see what version of cordova-android you have installed. I would guess it is 6.2.0? – JackDev Apr 06 '17 at 14:32
  • yey, u where right indeed. 6.2.1 is the version on my system. – holographix Apr 06 '17 at 14:33
  • @holographix - I see the the cordova-cli has just been updated to 6.5.0, perhaps this will make a difference? – JackDev Apr 06 '17 at 14:35
  • "cordova platform update" saved the day ( with an awkward 5.2.2 version ), but at least now complies. It still crashes while trying to deploy it to the device, but at least this proves that I might be on the right path – holographix Apr 06 '17 at 14:38
  • @holographix - yes seems like it, please see my updated answer. I suspect your issue is now gradle related? – JackDev Apr 06 '17 at 14:59
  • 1
    ok I got it working, needed to update cordova (npm install -g cordova), plus install gradle as u mentioned, plus fix the various paths as mentioned here: http://stackoverflow.com/questions/26209083/where-does-home-brew-installs-android-sdk. and voilà – holographix Apr 06 '17 at 15:16
  • This worked for me. Make sure to also upgrade cordova to 6.5.0 as mentioned. – black May 10 '17 at 11:40
14

update cordova

npm install -g cordova

and then try to add platform or if any problem with new version of cordova then use below

There is a problem with cordova version 6.4.0 and android 6.2.1. So, please try with below compatible versions

cordova version must be 6.4.0

npm install -g cordova@6.4.0

Install android in your project

cordova platform add android@6.1.2  

or

ionic platform add android@6.1.2
Ahmad
  • 5,551
  • 8
  • 41
  • 57
Veerendra Borra
  • 1,286
  • 14
  • 24
  • 1
    This will now update a user to cordova@7 (since it's the latest), so probably would be best to suggest npm install -g cordova@6. I believe cordova@7 introduces some other issues, so just to be clear on this. – JackDev May 19 '17 at 09:57
  • 1
    Don't tell people to use sudo to install things, that will create more problems. If you are not able to install things without sudo search how you can get rid of it, but don't use sudo – jcesarmobile Jul 10 '17 at 15:00
  • @jcesarmobile - using sudo is very standard, no different than windows prompting for permission before installing software. Is this some sort of npm or Cordova/Ionic specific issue? Thanks – JSON Aug 16 '17 at 01:44
  • 2
    @JSON on npm docs about how to install packages globally (https://docs.npmjs.com/getting-started/installing-npm-packages-globally) you can read "If you get an EACCES error, you should fix your permissions. You could also try using sudo, *but this should be avoided*" and links to how to fix permission problems https://docs.npmjs.com/getting-started/fixing-npm-permissions – jcesarmobile Aug 16 '17 at 07:46
  • Also recommended to reopen the shell and make sure cordova -v gives the right version – Nathan B Jan 04 '19 at 15:53
4

Do whatever @IonicBurger has said above. Also make sure that for Cordova based projects, each cordova version has specific dependency on android SDK and android build tools installed.

I am currently using Ionic 3 and I faced the same issue.

  • Make sure cordova is latest: npm i cordova -g will do the job. Note what version of cordova is installed by checking cordova -v. After that ensure you have installed ionic-native; this usually comes with ionic installation, but it wont harm to installed this again locally with npm i ionic-native --save

  • See all available platforms: ionic cordova platform list. Some plugins like camera, media etc have very specific cordova requirements (refer here)

  • When you install a plugin, you may encounter such error sometimes: 'Plugin doesn't support this project's cordova-android version. cordova-android: 6.1.2, failed version requirement: >=6.3.0 Skipping 'cordova-plugin-camera' for android'. Thats okay. This can be resolved by above two steps. Most importantly remember this: Ensure you have latest Android Build Tools and SDK installed. Please see the following image for more detail: enter image description here

Note that this answer works best with Windows environment.

Abhay Shiro
  • 3,431
  • 2
  • 16
  • 26
1

Updating to cordova@6.5.0 didn't work - I got error that this version is not found

Instead reverting to cordova@6.1.2 did work

cordova platform update android@6.1.2 --save
0

It is not the right solution downgrade the cordova version. If you want to use the lastest version of cordova and ionic, instead of using

ionic cordova platform add android

Just do:

cordova platform add android

works like a charm!

Good coding!

Faustino Gagneten
  • 2,564
  • 2
  • 28
  • 54
0

This problem occured for me when switching between two ionic projects. I fixed it by trying another node version and it works.

I used nvm use x.x.x and by downgrading to a previous nodejs version, I was able to build my project.

Hope it'll help someone.

g0tcha-
  • 323
  • 3
  • 5