0

There appears to be a conflict between file-transfer and Whitelist plugins, as also reported by some other users also. My list of plugins is as follows (and a few more need to be installed):

cordova-plugin-android-permissions 1.1.5 "Permissions"
cordova-plugin-app-event 1.2.2 "Application Events"
cordova-plugin-device 2.1.0 "Device"
cordova-plugin-file-md5 0.3.3 "MD5 Checksum"
cordova-plugin-file-transfer 1.7.1 "File Transfer"
cordova-plugin-file 7.0.0 "File"
cordova-plugin-inappbrowser 5.0.0 "InAppBrowser"
cordova-plugin-launcher 0.2.2 "Launcher"
cordova-plugin-media 6.1.0 "Media"
cordova-plugin-network-information 3.0.0 "Network Information"
cordova-plugin-splashscreen 6.0.2 "Splashscreen"
cordova-plugin-whitelist 1.3.5 "Whitelist"
cordova-plugin-x-socialsharing 6.0.4 "SocialSharing"
cordova-plugin-zip 3.1.0 "cordova-plugin-zip"
es6-promise-plugin 4.2.2 "Promise"

After installing cordova-plugin-file-transfer the build refused to complete its job and gives these errors:

D:\PhoneGap\qforall\platforms\android\app\src\main\java\org\apache\cordova\filetransfer\FileTransfer.java:48: error: cannot find symbol
import org.apache.cordova.Whitelist;
                         ^
  symbol:   class Whitelist
  location: package org.apache.cordova
D:\PhoneGap\qforall\platforms\android\app\src\main\java\org\apache\cordova\filetransfer\FileTransfer.java:691: error: cannot find symbol
                Whitelist whitelist = (Whitelist)gwl.invoke(webView);
                ^
  symbol:   class Whitelist
  location: class org.apache.cordova.filetransfer.FileTransfer
D:\PhoneGap\qforall\platforms\android\app\src\main\java\org\apache\cordova\filetransfer\FileTransfer.java:691: error: cannot find symbol
                Whitelist whitelist = (Whitelist)gwl.invoke(webView);
                                       ^
  symbol:   class Whitelist
  location: class org.apache.cordova.filetransfer.FileTransfer
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors

I also tried to replace Whitelist with Allowlist as suggested in this post by @Siddhartha Mukherjee but that also gives the same cannot find symbol error.

It was working fine earlier but as soon as I created a new project with latest Cordova and Gradle for latest Android it stopped.

halfer
  • 19,824
  • 17
  • 99
  • 186
AnR
  • 1,809
  • 3
  • 26
  • 45

1 Answers1

1

wihch version of cordova-android are you using? Whitelist is included in cordova-android 10+, so you should remove the plugin. This indeed breaks cordova-plugin-filetrasfer. To solve this you have two options.

1: I did this, by removing all references to Whitelist with a patch. Download the plugin as you did before. Remove all the references to Whitelist in the plugin in the node-modules folder (so, node-modules/cordova-plugin-file-transfer) than create a patch with patch package (npm i patch-package and follow the readme https://www.npmjs.com/package/patch-package: npx patch-package cordova-plugin-file-transfer, this will create a patch file that is applied whenever you install plugins, so between /node-modules and /plugins).

2: Even easier is to download the plugin from git rather than NPM. The devloper has removed the references to Whitelist on the main branch, but has not made a tag/release with this, so it is not updated on NPM.

FYI: In my project I use cordova-plugin-file-transfer-ios-fix : https://www.npmjs.com/package/cordova-plugin-file-transfer-ios-fix not sure if you (still) need to use this one. But if you have trouble on iOS, you can try it.

See also this SO Question: android 10 doesn't support whitelist plugin

And this Issue in the git repo: https://github.com/apache/cordova-plugin-file-transfer/issues/345 PS: the hook I mentioned before was for removing a permission from android-manifest. Patch-package is the best way to fix plugins

Mister_CK
  • 668
  • 3
  • 13
  • Its a freshly created project with Cordova updated so I am using the latest version. I did try `cordova plugin add https://github.com/apache/cordova-plugin-file-transfer.git` but that doesn't work with an error `CordovaError: Error: No git binary found in $PATH`. Is the any alternate path to git? – AnR Jan 03 '23 at 04:59
  • hmm, I ran your command and it seems to work in my project, but I cannot be sure, because it clashes with a different plugin for me. However there is a third solution, which is what I actually did, I thought I used a hook to fix it. But I actually used a patch. That is the most elegant way to fix plugins. I have a few of those patches. I've updated my answer to include this – Mister_CK Jan 03 '23 at 06:57
  • I am actually doing this on Android. So ios fix might not work. May be I should switch to some other plugin. – AnR Jan 03 '23 at 16:52
  • I think just patching it should be fine. this plugin has 4000 weekly downloads, which for is quite a lot for a cordova plugin, so it is probably still working for a lot of people. Patch package is really useful, I have used it to fix a few plugins that are no longer maintained, so it is worth the effort to read the docs and fix it properly – Mister_CK Jan 03 '23 at 18:26
  • Thanks. I will need to lean how to patch it. Never did before – AnR Jan 04 '23 at 04:28