Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mreis1/5c20c5c197d20409409d4e8c85a2c412 to your computer and use it in GitHub Desktop.

Select an option

Save mreis1/5c20c5c197d20409409d4e8c85a2c412 to your computer and use it in GitHub Desktop.
Cordova Android

Recently, after installing some libraries in my cordova project I started having this build error:

"This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry."

Then after some research I came across this link: https://cordova.apache.org/announcements/2020/06/29/cordova-android-9.0.0.html (section = "Added AndroidX Support")

Turns out that androidX can be set in gradle properties starting on cordova-android@9. Since my project was using cordova-android@8 I upgraded and had to add "AndroidXEnabled" in config.xml as follows:

<preference name="AndroidXEnabled" value="true" />

Then another issue came out:

> Task :app:compileDebugJavaWithJavac FAILED
/Users/me/app/platforms/android/app/src/main/java/nl/xservices/plugins/FileProvider.java:3: error: package android.support.v4.content does not exist
public class FileProvider extends android.support.v4.content.FileProvider {
                                                            ^
/Users/me/app/platforms/android/app/src/main/java/nl/xservices/plugins/SocialSharing.java:169: error: cannot find symbol
                fileUri = FileProvider.getUriForFile(webView.getContext(), cordova.getActivity().getPackageName()+".sharing.provider", new File(fileUri.getPath()));
                                      ^
  symbol:   method getUriForFile(Context,String,File)
  location: class FileProvider
/Users/me/app/platforms/android/app/src/main/java/nl/xservices/plugins/SocialSharing.java:285: error: cannot find symbol
                fileUri = FileProvider.getUriForFile(webView.getContext(), cordova.getActivity().getPackageName()+".sharing.provider", new File(fileUri.getPath()));
                                      ^
  symbol:   method getUriForFile(Context,String,File)
  location: class FileProvider
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

The error explicitly identifies the source of the problem. Head to /Users/me/app/platforms/android/app/src/main/java/nl/xservices/plugins/FileProvider.java and update it as follows:

package nl.xservices.plugins;

//public class FileProvider extends android.support.v4.content.FileProvider {
public class FileProvider extends androidx.core.content.FileProvider {
}

If your prefer an automated fix, then install this plugin as suggested in the documentation. $ cordova plugin add cordova-plugin-androidx-adapter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment