Cordova Error: package org.apache.cordova.file does not exist


#1

Versions:
Meteor 1.5

cordova-android version: 6.1.1

Cordova plugins:

cordova-plugin-camera@2.3.1
cordova-plugin-compat@1.1.0
cordova-plugin-device@1.1.5
cordova-plugin-geolocation@2.4.1
cordova-plugin-googleplus@https://github.com/yehiasalam/cordova-plugin-googleplus.git#305e04da839f048284e50111dc2a89b24361adf3
cordova-plugin-media-capture@1.4.3
cordova-plugin-meteor-webapp@1.4.2
cordova-plugin-splashscreen@4.0.1
phonegap-plugin-push@1.6.4

This week I’ve been trying to compile my app for cordova android but kept running into the following error:

%% Plugin doesn't support this project's cordova-android version. cordova-android: 6.1.1, failed version requirement: >=6.3.0
%% Skipping 'cordova-plugin-file' for android 
 error: package org.apache.cordova.file does not exist
 import org.apache.cordova.file.FileUtils;

On Nov 6th 2017 cordova-plugin-file released 5.0.0. cordova-plugin-media-capture@1.4.3 depends on

    <dependency id="cordova-plugin-file" version="^4.0.0" />
    <dependency id="cordova-plugin-compat" version="^1.0.0" />.

From what I can tell cordova-plugin-file is only required by my cordova-plugin-media-capture by running this command
cordova plugin remove cordova-plugin-file

Analysis: Running meteor run android-device --verbose I found this

% Calling plugman.fetch on plugin "cordova-plugin-media-capture@1.4.3"            
%% Fetching plugin "cordova-plugin-media-capture@1.4.3" via npm                    
%% Copying plugin "/Users/.cordova/lib/npm_cache/cordova-plugin-media-capture/1.4.3/package" => "/Users/blah/.meteor/local/cordova-build/plugins/cordova-plugin-media-capture"
%% Calling plugman.install on plugin "blah/.meteor/local/cordova-build/plugins/cordova-plugin-media-capture" for platform "android
%% Installing "cordova-plugin-media-capture" for android                           
%% Running command: blah/.meteor/local/cordova-build/platforms/android/cordova/version 
%% Command finished with error code blah/.meteor/local/cordova-build/platforms/android/cordova/version 
%% Dependencies detected, iterating through them...                                
%% Plugin dependency "cordova-plugin-file" not fetched, retrieving then installing.
%% Fetching plugin "cordova-plugin-file" via npm                                   
%% Copying plugin "/Users/.cordova/lib/npm_cache/cordova-plugin-file/5.0.0/package" => "blah/.meteor/local/cordova-build/plugins/cordova-plugin-file"
%% Installing "cordova-plugin-file" for android                                    
%% Plugin doesn't support this project's cordova-android version. cordova-android: 6.1.1, failed version requirement: >=6.3.0
%% Skipping 'cordova-plugin-file' for android

Problem: Its pulling in cordova-plugin-file@5.0.0 from npm! This breaks the build process for me as I dont have the necessary cordova-android version. I was able to compile fine before the release of cordova-plugin-file@5.0.0

Question: This is what is interesting, no where in my application do I call/refer to cordova-plugin-file its simply brought in as a dependent of cordova-plugin-media-capture. My question to everyone is why is it pulling in @5.0.0 when cordova-plugin-media-capture specifies to bring in cordova-plugin-file^4.0.0

My fetch.json
> “cordova-plugin-media-capture”: {

    "source": {
        "type": "registry",
        "id": "cordova-plugin-media-capture@1.4.3"
    },
    "is_top_level": true,
    "variables": {
        "CAMERA_USAGE_DESCRIPTION": " ",
        "MICROPHONE_USAGE_DESCRIPTION": " ",
        "PHOTOLIBRARY_USAGE_DESCRIPTION": " "
    }
},
"cordova-plugin-file": {
    "source": {
        "type": "registry",
        "id": "cordova-plugin-file"
    },
    "is_top_level": false,
    "variables": {}
},
"cordova-plugin-splashscreen": {
    "source": {
        "type": "registry",
        "id": "cordova-plugin-splashscreen@4.0.1"
    },
    "is_top_level": true,
    "variables": {}
}

Why does cordova-plugin-file not say @4.4.3? Is Meteor bringing cordova-plugin-file anywhere? Since fetch.json is not specifying the version of cordova-plugin-file it will fetch the latest from npm (5.0.0) I do not want to introduce cordova-plugin-file into my project myself (rather keep it as a dependency) but why does it keep fetching the latest when its specified at @4.4.3?

Similar problems:
https://forums.adobe.com/thread/2410117

Workaround: Upgrade cordova-plugin-media-capture@1.4.3 to 2.0.0



This resolved the issue for me but unfortunately I have to re submit my app to the app stores (which I’m trying to avoid)


#2

Had a similar issue, but I’m using cordova-plugin-file as a direct dependency in my project. So, cordova-plugin-file@4.3.3 in my .meteor/condova-plugins file used to work until one month ago. Yesterday I’ve tried a build and got the error you stated here. Digging down a little, it seems that cordova is pulling cordova-plugin-file@5.0.0 even when we specify @4.3.3. As a workaround, I’m now pulling a specific git commit instead of the npm version number, like so: cordova-plugin-file@https://github.com/apache/cordova-plugin-file.git#5c0f68d1cc105c30bed4e0f0a76a97afc922ae8b. This solved it for me. But yes, I’ll have to resubmit the app to the stores…