简体   繁体   中英

Cordova Error using Cordova-Android 6.2.0 - getFileResources is not a function

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

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.

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

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: 在此输入图像描述

Note that this answer works best with Windows environment.

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

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!

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 xxx and by downgrading to a previous nodejs version, I was able to build my project.

Hope it'll help someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM