cordova-plugin-file-transfer: Cordova Android 10.0.0 not compiling - cannot find symbol "import org.apache.cordova.Whitelist;"

Bug Report

Problem

The plugin is not working with Cordova Android 10 anymore because Whitelist was renamed to Allowlist.

What is expected to happen?

The plugin compiles.

What does actually happen?

Cannot find symbol errors occur:

> Task :app:compileDebugJavaWithJavac FAILED
cordovaProjectFoler/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
cordovaProjectFoler/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
cordovaProjectFoler/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

Information

The reference to Whitelist can not be found here anymore here: because Whitelist was renamed to Allowlist here: https://github.com/apache/cordova-android/pull/1138

I suggest to remove the code that exists for Cordova 3.x and 4.x as these are quite old versions. I am happy to create a pull request for this (https://github.com/Luro91/cordova-plugin-file-transfer/commit/9db03f76d19199d1fae9c185acad7bd8b43532bf). Should a minimum version for Cordova Android be specified for the plugin in this case?

Command or Code

cordova build android

Environment, Platform, Device

Build machine: MacBook Pro, Mac OS Big Sur Version 11.4

Version information

Cordova CLI: 10.0.0 Cordova Android 10.0.0 <plugin name="cordova-plugin-file-transfer" spec="https://github.com/apache/cordova-plugin-file-transfer#648b57792f2f33ffc9da6d2fa020d26a48799048" />

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 27 (2 by maintainers)

Most upvoted comments

I am also facing same issue.

Replace Whitelist class with AllowList in cordova-plugin-file-transfer > src > android > FileTransfer.java

import org.apache.cordova.Whitelist; => import org.apache.cordova.AllowList;

/* This code exists for compatibility between 3.x and 4.x versions of Cordova.
         * Previously the CordovaWebView class had a method, getWhitelist, which would
         * return a Whitelist object. Since the fixed whitelist is removed in Cordova 4.x,
         * the correct call now is to shouldAllowRequest from the plugin manager.
         */
        Boolean shouldAllowRequest = null;
        if (isLocalTransfer) {
            shouldAllowRequest = true;
        }
        if (shouldAllowRequest == null) {
            try {
                Method gwl = webView.getClass().getMethod("getWhitelist");
                AllowList whitelist = (AllowList)gwl.invoke(webView);
                shouldAllowRequest = whitelist.isUrlAllowListed(source);
            } catch (NoSuchMethodException e) {
            } catch (IllegalAccessException e) {
            } catch (InvocationTargetException e) {
            }
        }

Replace Above code with below code it’s work s for me

/* This code exists for compatibility between 3.x and 4.x versions of Cordova.
       * Previously the CordovaWebView class had a method, getWhitelist, which would
       * return a Whitelist object. Since the fixed whitelist is removed in Cordova 4.x,
       * the correct call now is to shouldAllowRequest from the plugin manager.
       */
      Boolean shouldAllowRequest = null;
      if (isLocalTransfer) {
          shouldAllowRequest = true;
      }
      if (shouldAllowRequest == null) {
          try {
              Method gwl = webView.getClass().getMethod("getWhitelist");
              AllowList whitelist = (AllowList)gwl.invoke(webView);
              shouldAllowRequest = whitelist.isUrlAllowListed(source);
          } catch (NoSuchMethodException e) {
          } catch (IllegalAccessException e) {
          } catch (InvocationTargetException e) {
          }
      }

https://github.com/Priyansu431/cordova-plugin-file-transfer.git

I have the same problem cannot find symbol import org.apache.cordova.AllowList; cordova 10.0 and “@ionic-native/file-transfer”: “^5.22.0”

@Priyansu431 Cordova version - 10 cordova-plugin-file-transfer - 1.7.2-dev

Use master branch to install cordova-plugin-file-transfer and do the above changes it will work cordova plugin add https://github.com/apache/cordova-plugin-file-transfer.git

Or

you can install from below git branch till new changes merge with in master branch cordova plugin add https://github.com/Priyansu431/cordova-plugin-file-transfer.git

I hope it will work for you…

You can try the main branch, but we do not recommend using it in production.

Installing the main branch is only for testing purposes. The idea is to allow developers to test, detect, and report any issues they might see in their use case.

cordova plugin add github:apache/cordova-plugin-file-transfer

But again, we can not guarantee that it remains stable, and it has not gone through an official vote.

The main branch had already fixed the issue regarding the change in the class name, and also it bumped the cordova-plugin-file support to >=7.0.0.

The only reason why there hasn’t been a release since the plugin has been undeprecated is that the CI tests have been failing and there is no baseline to what is acceptable for the release.

I have a branch that fixes SOME of the tests, but it would be nice for all Android and iOS tests to pass or at least identify if the failing tests are no longer valid or if it is because of the CI environment before any release. It helps create a baseline.