Hi there! 馃憢
I'm working at PSPDFKit, maintainers of the PSPDFKit/Cordova-Android plugin. Recently we upgraded to the newer AndroidX libraries which replace the now deprecated Android Support Libraries.
We've now received reports from our customers that fail to upgrade to newer versions of our library to to incompatibility with various other Cordova and Ionic plugins that still use the older support library.
We performed a brief analysis of the current AndroidX situation which we shared in the the Apache cordova-android issue tracker (https://github.com/apache/cordova-android/issues/565#issuecomment-454891636) which is also valid for the Ionic plugin ecosystem.
To summarize the current situation:
I'm starting discussion of this issue inside this specific Ionic plugin because our customer is relying on this specific plugin. However, since this is a general plugin ecosystem issue, it should maybe be elevated to an umbrella issue inside the primary ionic-team/ionic repo. Is AndroidX a current topic for the Ionic team? Thanks!
Does this affect any other Cordova plugins offered by Ionic besides cordova-plugin-ionic-webview? Otherwise this right here is probably the correct location - the core plugins Ionic apps built with Cordova are using are the ones over at the Cordova repositories.
I'm sorry, but I don't have an overview of the Cordova plugins that are maintained by Ionic. It essentially affects all Cordova plugins that depend on the Android Support Libraries, either directly, or indirectly via transitive dependencies.
A quick search inside the Ionic organization that should probably cover all uses of the support libraries: https://github.com/search?q=org%3Aionic-team+%22android.support%22&type=Code. From skimming over the results, I'd say there's a handful of repositories that would require an update.
Quick look through the search results showed mostly capacitor (which is a Cordova alternative) and ionic-native-push-notifications which seems to be a test/sample project - and only this Cordova plugin. So this probably really only affects this repository - but Ionic people might of course know better.
As far as I can tell this plugin only uses the android support library at one place.
This could also be fixed without upgrading to the AndroidX way of importing from the support library. By replacing the RequiresApi decorator with an if statement checking the api version a breaking change could be avoided.
I created an AndroidX adapter plugin: cordova-plugin-androidx-adapter.
It scans the Gradle config and Java source code of a Cordova Android platform project and replaces any legacy Support Library references with AndroidX equivalents.
Obviously won't work if the code is wrapped up in archives such as AAR or JAR but many Cordova plugins are pretty simple with plain Java source code so hopefully should work in most cases.
Any word from Ionic team on this? I really appreciate @dpa99c's efforts on the adapter plugin (many thanks!!), but long term, it'd be good to update this plugin and not need to add on cumulative plugins to resolve the issue.
There was a PR to adapt cordova-plugin-camera which worked, but we were unsure how to properly adapt these changes: https://github.com/apache/cordova-plugin-camera/pull/418 Current conclusion was, that there is a need for a more general discussion on cordova-android level how the switch could/should be made.
Next version of cordova-plugin-ionic-webview (5.0) removes SDK 19 support and doesn't use any android support library anymore, so this is no longer a problem in the plugin.
cordova-android already supports AndroidX in master (still not released)
Capacitor 2.0 uses Android X too.
So closing this issue.
Any update if its released? I still get such errors
C:\SVN_VIEWS\SVN2020\610MOB\platforms\android\app\src\main\java\com\ionicframework\cordovawebview\IonicWebViewEngine.java:11: error: package android.support.annotation does not exist
import android.support.annotation.RequiresApi;
^
C:\SVN_VIEWS\SVN2020\610MOB\platforms\android\app\src\main\java\de\appplant\cordova\emailcomposer\Provider.java:22: error: package android.support.v4.content does not exis
import android.support.v4.content.FileProvider;
^
C:\SVN_VIEWS\SVN2020\610MOB\platforms\android\app\src\main\java\de\appplant\cordova\emailcomposer\Provider.java:24: error: cannot find symbol
public class Provider extends FileProvider {
^
symbol: class FileProvider
C:\SVN_VIEWS\SVN2020\610MOB\platforms\android\app\src\main\java\com\ionicframework\cordovawebview\IonicWebViewEngine.java:122: error: cannot find symbol
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
^
symbol: class RequiresApi
location: class IonicWebViewEngine.ServerClient
C:\SVN_VIEWS\SVN2020\610MOB\platforms\android\app\src\main\java\de\appplant\cordova\emailcomposerAssetUtil.java:274: error: cannot find symbol
return Provider.getUriForFile(ctx, authority, file);
^
symbol: method getUriForFile(Context,String,File)
location: class Provider
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\SVN_VIEWS\SVN2020\610MOB\platforms\android\app\src\main\java\org\apache\cordovafileAssetFilesystem.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Most helpful comment
I created an AndroidX adapter plugin: cordova-plugin-androidx-adapter.
It scans the Gradle config and Java source code of a Cordova Android platform project and replaces any legacy Support Library references with AndroidX equivalents.
Obviously won't work if the code is wrapped up in archives such as AAR or JAR but many Cordova plugins are pretty simple with plain Java source code so hopefully should work in most cases.