Pease help me!, I am new to flutter I am importing a project and when I try to run it is giving exception

/simple_permissions-0.1.9/android/src/main/java/com/ethras/simplepermissions/SimplePermissionsPlugin.java:9: error: cannot find symbol import android.support.v4.app.ActivityCompat;
^
symbol: class ActivityCompat
location: package android.support.v4.app

My project is already compatible with androidX, I have tried package get and upgrade package but nothing happens, I have got the similar problem

1 Answers

0
Siddharth Patankar On

When you migrate a flutter app to AndroidX, all the plugins the app depends on should also support AndroidX else your app build will fail and this is what is happening here.

Even though you have migrated your project to AndroidX, the simple-permissions plugin has not been migrated to AndroidX yet and this is what is causing the issue.

Below are the options you have in this case -

1. User the permission_handler plugin instead of simple-permissions.

The permission_handler plugin is a much more frequently updated plugin which has already been migrated to AndroidX. Here is the link to the plugin.

2. Migrate simple-permissions to AndroidX yourself

If you strictly want to use simple-permissions, you can clone the git repo and manually migrate the plugin to AndroidX and use the plugin via git url inside your pubspec.yaml. Details for migrating plugins to AndroidX can be found here.

You can use the plugin from git url in the following way inside you pubspec.yaml

dependencies:
  plugin1:
    git:
      url: git://github.com/flutter/plugin1.git 
     //Your repo url goes in place of this url

3. Avoid using AndroidX altogether in you app.

You can force your app to use the older support libraries if you do not wish to perform the above two steps, but by doing this you will need to downgrade all your plugins to versions which do not use AndroidX, which is not the ideal solution. More about this here.

Hope this helps!