two packages are using two different compileSdkVersion in flutter
Asked Answered
M

1

6

I am working with geolocator and permission_handler package in my app but now both packages have different requirement for compileSdkVersion which is 30 and 31 respectively. I am trying to change compileSdkVersion but its not working anymore

Now if I switch to 30 it gives following error

    Launching lib\main.dart on INE LX1r in debug mode...
    Parameter format not correct -
    Note: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\contacts_service-0.4.6\android\src\main\java\flutter\plugins\contactsservice\contactsservice\ContactsServicePlugin.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:321: error: cannot find symbol
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
                                                               ^
      symbol:   variable S
      location: class VERSION_CODES
    C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:72: error: cannot find symbol
                case Manifest.permission.BLUETOOTH_SCAN:
                                        ^
      symbol:   variable BLUETOOTH_SCAN
      location: class permission
    C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:74: error: cannot find symbol
                case Manifest.permission.BLUETOOTH_ADVERTISE:
                                        ^
      symbol:   variable BLUETOOTH_ADVERTISE
      location: class permission
    C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:76: error: cannot find symbol
                case Manifest.permission.BLUETOOTH_CONNECT:
                                        ^
      symbol:   variable BLUETOOTH_CONNECT
      location: class permission
    C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:259: error: cannot find symbol
                    String result = determineBluetoothPermission(context, Manifest.permission.BLUETOOTH_SCAN);
                                                                                             ^
      symbol:   variable BLUETOOTH_SCAN
      location: class permission
    C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:270: error: cannot find symbol
                    String result = determineBluetoothPermission(context, Manifest.permission.BLUETOOTH_ADVERTISE);
                                                                                             ^
      symbol:   variable BLUETOOTH_ADVERTISE
      location: class permission
    C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:281: error: cannot find symbol
                    String result = determineBluetoothPermission(context, Manifest.permission.BLUETOOTH_CONNECT);
                                                                                             ^
      symbol:   variable BLUETOOTH_CONNECT
      location: class permission
    C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:370: error: cannot find symbol
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && hasPermissionInManifest(context, null, permission )) {
                                                            ^
      symbol:   variable S
      location: class VERSION_CODES
    8 errors
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':permission_handler:compileDebugJavaWithJavac'.
    > Compilation failed; see the compiler error output for details.
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 22s
    Exception: Gradle task assembleDebug failed with exit code 1
    Exited (sigterm)

and when I switch to 31 it gives following error

    Launching lib\main.dart on INE LX1r in debug mode...
    Parameter format not correct -
    Note: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\contacts_service-0.4.6\android\src\main\java\flutter\plugins\contactsservice\contactsservice\ContactsServicePlugin.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\geolocator_android-1.0.0\android\src\main\java\com\baseflow\geolocator\location\LocationManagerClient.java:10: warning: [deprecation] LocationProvider in android.location has been deprecated
    import android.location.LocationProvider;
                           ^
    error: warnings found and -Werror specified
    C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\geolocator_android-1.0.0\android\src\main\java\com\baseflow\geolocator\location\LocationMapper.java:29: warning: [deprecation] isFromMockProvider() in Location has been deprecated
          position.put("is_mocked", location.isFromMockProvider());
                                            ^
    1 error
    2 warnings
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':geolocator_android:compileDebugJavaWithJavac'.
    > Compilation failed; see the compiler error output for details.
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 18s
    Exception: Gradle task assembleDebug failed with exit code 1
    Exited (sigterm)

What do I do now?

Manumission answered 15/10, 2021 at 11:59 Comment(0)
P
16

I went through the same experience and fixed it following the procedures below

In my application I use the following dependencies:

permission_handler: ^8.2.5
geolocator: ^7.7.0
geocoding: ^2.0.1

Make sure of the following:

build.gradle:
   compileSdkVersion 31

gradle.properties:
   android.useAndroidX=true
   android.enableJetifier=true

And all others android. dependencies must be replaced to their AndroidX counterparts.

After this:

flutter upgrade
flutter pub get
flutter clean
flutter build apk --release

If the problem persists:

1) Restart the computer, cross your fingers.
Prying answered 15/10, 2021 at 12:24 Comment(2)
Thanks for that. Main issue was compileSdkVersion 31. I changed from 30 to 31 to fix that in my caseLeopard
i crossed my fingers and it worked, ThanksTrinee

© 2022 - 2024 — McMap. All rights reserved.