android 10 doesn't support whitelist plugin
Asked Answered
T

7

31

Android 10 doesn't support "whitelist plugin", when I add android platform it skips whitelist plugin which cause "file transfer plugin" issues when building or running the application

ionic cordova platform add android@latest

Installing "cordova-plugin-whitelist" for android
Plugin doesn't support this project's cordova-android version. cordova-    android: 10.1.0, failed version requirement: >=4.0.0 <10.0.0
Skipping 'cordova-plugin-whitelist' for android

When creating the application, these errors will appear :

ionic cordova build android

Task :app:compileDebugJavaWithJavac D:\workspace\SCL\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:\workspace\SCL\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:\workspace\SCL\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

it seems like "file transfer" require "whitelist plugin" but "whitelist plugin" is being skipped when adding android > 10

this doesn't happen in android 9

anyone can help please ?

Tierratiersten answered 23/8, 2021 at 16:36 Comment(4)
whitelist plugin is built in cordova-android 10, but file-transfer will need to be updated to use the new cordova-android classes instead of the old whitelist plugin classesClayclaybank
but why it skip whitelist plugin when adding the android platform ?Tierratiersten
Because it’s built in now and causes conflicts if installedClayclaybank
Unlike, [email protected], I think [email protected] doesn't install the whitelist plugin automatically anymore.Myel
S
59

Cordova 10+ includes the Whitelist class and no external plugin is required. In addition to removing it you also need to update the file transfer plugin.

So, you need to do two things:

  1. Update the file transfer plugin. Even though this plugin is no longer recommended, the developer has thankfully updated the plugin to support the new Whitelist class, which is now included by default in Cordova. You will have to do this by installing directly from the github repo:

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

  2. Remove the whitelist plugin

    cordova plugin rm cordova-plugin-whitelist

H/T to the original response in this [thread][1]

checkout the file transfer plugin issues [1]: https://githubmemory.com/repo/apache/cordova-plugin-file-transfer/issues/306

Socle answered 3/11, 2021 at 10:24 Comment(4)
Life saver, worked 👍Mafaldamafeking
For Capacitor users: npm i https://github.com/apache/cordova-plugin-file-transfer.git to install plugin and then: npm install @awesome-cordova-plugins/file-transfer then ionic cap syncLovettalovich
I needed this line in my config.xml as well <preference name="AndroidInsecureFileModeEnabled" value="true" />Clot
@tannerburton thank you for that <preference> comment! I needed that! 🙏🏻Monochasium
G
39

The replies from Sanjay and Francisco helped me to find the right solution. Along with fixing the package.json and other existence of 'whitelist plugin' from the project, you also need to run the following to uninstall it from the android/ios platforms.

ionic cordova plugin rm cordova-plugin-whitelist

Update - For whatever reason, this started throwing errors again. See Rajath's answer. (thank you, Rajath!) In short, add the plugin again from the github repo instead

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

Gadfly answered 5/10, 2021 at 0:36 Comment(4)
Thanks for answer. But what about iOS build? Does it require to whitelist the urls in iOS ?Patriliny
Yes same question re iOS, and WIndows, but looks like this may only have even been for Android? (see cordova.apache.org/docs/en/9.x/reference/… only support Andorid)Cauthen
I've no idea, haven't gotten to iOS yet. If you've solved it, would appreciate the solution here. :)Gadfly
https://github.com/apache/cordova-plugin-file-transfer.git is not reachableBergin
C
14

The same thing happened to me. after replacing Whitelist Class . it works for me, so you might want to try it.

Replace Whitelist class with AllowList in

cordova-plugin-file-transfer > src > android > FileTransfer.java

 // replace
 import org.apache.cordova.Whitelist;

 import org.apache.cordova.AllowList;

// Replace
Whitelist whitelist = (Whitelist)gwl.invoke(webView);
shouldAllowRequest = whitelist.isUrlWhiteListed(source); 

AllowList whitelist = (AllowList)gwl.invoke(webView);
shouldAllowRequest = whitelist.isUrlAllowListed(source);  

      
Contented answered 24/10, 2022 at 20:30 Comment(2)
replacing Whitelist with Allowlist gives the same cannot find symbol errorBergin
You didn't replace all the Whitelist, I thinkContented
A
8

cordova version 10.0.0 or later does not need cordova-plugin-whitelist plugin you can just simply remove them . cordova 10.0.0 or android 10.0.0 (API 30) have inbuild core whitelist so you can remove and make build again

Antinode answered 4/9, 2021 at 12:46 Comment(0)
I
3

I think you have the same problem i had to sorted out.

Go to your Cordova Folder path and edit the package.json file removing the two lines that references cordova-plugin-whitelist.

And all will be perfect after that.

Insipience answered 29/8, 2021 at 13:35 Comment(0)
W
0

I had the same issue and it was fixed by installing the following:

ionic cordova plugin add cordova-plugin-androidx
ionic cordova plugin add cordova-plugin-androidx-adapter

The error comes because this app is not using androidX but these plugins solve errors.

Wehrle answered 18/2, 2023 at 1:32 Comment(0)
I
0

So even though it's suggest to replace the WhiteList with AllowedList there are no specification where should this replacement should happen so after many tries this is the working solution(code base) after WhiteList replaced with allowdList please find the code here.

Updated working WhiteListPlugin.java

Intellectuality answered 18/7, 2023 at 6:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.