apache / cordova-plugin-file-transfer

Apache Cordova File Transfer Plugin
https://cordova.apache.org/
Apache License 2.0
595 stars 888 forks source link

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

Closed Luro91 closed 2 years ago

Luro91 commented 2 years ago

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

Checklist

  • [x] I searched for existing GitHub issues
  • [x] I updated all Cordova tooling to most recent version
  • [x] I included all the necessary information above
Priyansu431 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

I am also facing same issue.

Priyansu431 commented 2 years ago

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

pawan-logiciel commented 2 years ago

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

Priyansu431 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

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

pawan-logiciel commented 2 years ago

Can anybody help me with this?

rolinger commented 2 years ago

@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 commented 2 years ago

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 commented 1 year ago

has anyone found any solution yet?

pawan-logiciel commented 1 year ago

@pixellet14 You have to modify plugin yourself or you can use this https://github.com/apache/cordova-plugin-file-transfer/issues/306#issuecomment-884796504

pixellet14 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Check Android version of device and emulators

On Tue, 6 Dec, 2022, 7:10 pm dixitakarki, @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/apache/cordova-plugin-file-transfer/issues/306#issuecomment-1339404571, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHB5L4HFIMS4GQL7FAYFGFLWL464VANCNFSM5AXKPUKQ . You are receiving this because you were mentioned.Message ID: @.***>

breautek commented 1 year ago

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 https://github.com/apache/cordova-plugin-file-transfer/issues/306#issuecomment-1337040068

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.