Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cordova Android 10.0.0 not compiling - cannot find symbol "import org.apache.cordova.Whitelist;" #306

Closed
3 tasks done
Luro91 opened this issue Jul 21, 2021 · 27 comments · Fixed by #307
Closed
3 tasks done

Comments

@Luro91
Copy link

Luro91 commented Jul 21, 2021

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: apache/cordova-android#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 (Luro91@9db03f7). 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

Checklist

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

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

@pawan-logiciel
Copy link

Hey @Priyansu431 I am also facing this issue with your above solution my /platforms/android/app/src/main/java/org/apache/cordova/filetransfer/FileTransfer.java:48: error: cannot find symbol import org.apache.cordova.Whitelist; problem get resolved but I am facing another issue as well

Task :app:compileDebugJavaWithJavac FAILED /platforms/android/app/src/main/java/org/apache/cordova/filetransfer/FileTransfer.java:49: error: package org.apache.cordova.file does not exist import org.apache.cordova.file.FileUtils; ^ /platforms/android/app/src/main/java/com/silkimen/cordovahttp/CordovaHttpDownload.java:13: error: package org.apache.cordova.file does not exist import org.apache.cordova.file.FileUtils; ^ /platforms/android/app/src/main/java/org/apache/cordova/filetransfer/FileTransfer.java:851: error: cannot find symbol FileUtils filePlugin = (FileUtils) pm.getPlugin("File"); ^ symbol: class FileUtils /platforms/android/app/src/main/java/org/apache/cordova/filetransfer/FileTransfer.java:851: error: cannot find symbol FileUtils filePlugin = (FileUtils) pm.getPlugin("File"); ^ symbol: class FileUtils /platforms/android/app/src/main/java/com/silkimen/cordovahttp/CordovaHttpDownload.java:34: error: cannot find symbol JSONObject fileEntry = FileUtils.getFilePlugin().getEntryForFile(file); ^ symbol: variable FileUtils location: class com.silkimen.cordovahttp.CordovaHttpDownload

can you please help me on this?

@sirineKr
Copy link

I am also facing same issue.

@Priyansu431
Copy link

Which Cordova version are you using and cordova-plugin-file-transfer version?

@pawan-logiciel
Copy link

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

@Priyansu431
Copy link

Priyansu431 commented Jul 23, 2021

@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..

@pawan-logiciel
Copy link

@Priyansu431 I am still facing this issue
is it due to cordova-plugin-file?

i am using cordova-plugin-file version - 6.0.2

@pawan-logiciel
Copy link

@Priyansu431 it's working now for me I have changed my cordova-plugin-file version to 4.0.0 cause I have a low-level code base and it's not supporting the latest version

But I have one problem now with your above solution I am getting a connection error when I download files. Can you please help me with this?

@Priyansu431
Copy link

Priyansu431 commented Jul 27, 2021

@Priyansu431 it's working now for me I have changed my cordova-plugin-file version to 4.0.0 cause I have a low-level code base and it's not supporting the latest version

But I have one problem now with your above solution I am getting a connection error when I download files. Can you please help me with this?

Can you provide me any sample project? so I can replicate your above issue

@pawan-logiciel
Copy link

@Priyansu431 Try to install cordova-plugin-file@4.0.0 with the latest file-transfer plugin you will get the issue

@pawan-logiciel
Copy link

Can anybody help me with this?

@rolinger
Copy link

rolinger commented Sep 3, 2021

@Priyansu431 - I tried both of your links above for the newer version and both are not working. However, the manual fix you provided is working and thats what I am using for now. That being said, I am not certain why this issue is closed, this whitelist issue still present in the current v1.71.

Is there any documentation on how to use the new AllowList that replaces the whitelist plugin? I just ported my app to Cordova v10.1.0 using cordova-android v10, and my app is getting some errors that I think might be related.

@joeljimenez
Copy link

I have the same problem cannot find symbol
import org.apache.cordova.AllowList;

cordova 10.0 and "@ionic-native/file-transfer": "^5.22.0"

@pixellet14
Copy link

has anyone found any solution yet?

@pawan-logiciel
Copy link

@pixellet14 You have to modify plugin yourself or you can use this
#306 (comment)

@pixellet14
Copy link

pixellet14 commented Oct 26, 2022

@pawan-logiciel
I highly appreciate your reply. But I have tried that option for several times now. It doesn't work with cordova-plugin-file 7.0.0+

@erisu
Copy link
Member

erisu commented Oct 26, 2022

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.

@sachinshah391
Copy link

I'm trying to wrap up one of react based Projects with Cordova. But I'm getting this white screen, tried many things but still I really need help if someone can help we can connect over LinkedIn.--https://www.linkedin.com/in/sachinshah391/

@pixellet14
Copy link

I'm trying to wrap up one of react based Projects with Cordova. But I'm getting this white screen, tried many things but still I really need help if someone can help we can connect over LinkedIn.--https://www.linkedin.com/in/sachinshah391/

the plugin has issues with cordova @ 11 ... use base64 instead

@sachinshah391
Copy link

the plugin has issues with cordova @ 11 ... use base64 instead file-transfer plugin? Stil same issue
image

this is the white screen I'm taking about

@pixellet14
Copy link

the plugin has issues with cordova @ 11 ... use base64 instead file-transfer plugin? Stil same issue image

this is the white screen I'm taking about

kindly explain your concerns on linkedin

@Priyansu431
Copy link

image
For "ERR CLEARTEXT NOT PERMITTED" you need to add <application android:usesCleartextTraffic="true" /> into config.xml

Example:

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
            <application android:usesCleartextTraffic="true" />
        </edit-config>

@Priyansu431
Copy link

I'm trying to wrap up one of react based Projects with Cordova. But I'm getting this white screen, tried many things but still I really need help if someone can help we can connect over LinkedIn.--https://www.linkedin.com/in/sachinshah391/

Which Cordova version are you using and are you using ionic-angular or ionic-react?

@sachinshah391
Copy link

sachinshah391 commented Dec 5, 2022

I'm the using latest version 11.0.0 for Cordova. I already have an existing React Project just wrapping it. Was referring to this
blog-https://medium.com/@pshubham/using-react-with-cordova-f235de698cc3.
ERR CLEARTEXT NOT PERMITTED--- Resolved
Thanks but still that white is the screen is there with other console errors

@dixitakarki
Copy link

what can be the possible reason that My react code is running on emulator but the apk is not running on mobile devices.
what is the easiest way to debug issues on mobile devices.

@Priyansu431
Copy link

Priyansu431 commented Dec 6, 2022 via email

@breautek
Copy link
Contributor

breautek commented Dec 6, 2022

what can be the possible reason that My react code is running on emulator but the apk is not running on mobile devices. what is the easiest way to debug issues on mobile devices.

You can enable USB debugging. I have a blog post that describes how.

On Android, assuming that the system webview is chromium based, you can use the Desktop chrome to remote debug the mobile webview, including application webviews, which gives you the same web inspector capabilities to debug the mobile webview.

This particular issue is because the current release of this plugin is old and deprecated. I'm not going to go into the full story here but there have been a decision to revive this plugin but that's still a work in progress. The current release of tihs plugin depends on code that has been removed in the current android platform version.

As a stopgap measure, you can install the development version of this plugin but this is not considered stable and it could break at any time. Additonally, there are CI tests that are failing, which is the primarily reason why we haven't made a formal release yet. So some features may not work properly. So this is a warning to use at your own risk.

If you choose to try the development version, I'd recommend at least using the commit pin to avoid unexpected changes.

cordova plugin add https://github.com/apache/cordova-plugin-file-transfer.git#7ba6fa3755605bca6bfeef2c2a808a1f22c6848c

As for the cleartext behaviour, this is becoming out of topic, but a solution can be found at #306 (comment)

I'm locking this thread for respect of the original poster. This thread isn't really the place for support questions, especially when they become out of topic. If you require further support, I'd suggest to ask a question on our Discussions board, feel free to link to this issue for context, if relevant.

@apache apache locked as off-topic and limited conversation to collaborators Dec 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.