两个包在颤振中使用两个不同的 compileSdkVersion
Posted
技术标签:
【中文标题】两个包在颤振中使用两个不同的 compileSdkVersion【英文标题】:two packages are using two different compileSdkVersion in flutter 【发布时间】:2021-12-03 15:19:52 【问题描述】:我在我的应用程序中使用geolocator 和permission_handler 包,但现在这两个包对compileSdkVersion
的要求不同,分别是30
和31
。我正在尝试更改 compileSdkVersion 但它不再工作了
现在如果我切换到 30 会出现以下错误
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)
当我切换到 31 时出现以下错误
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)
我现在该怎么办?
【问题讨论】:
【参考方案1】:我经历了同样的经历,并按照以下步骤修复了它
在我的应用程序中,我使用以下依赖项:
permission_handler: ^8.2.5
geolocator: ^7.7.0
geocoding: ^2.0.1
确保以下几点:
build.gradle:
compileSdkVersion 31
gradle.properties:
android.useAndroidX=true
android.enableJetifier=true
还有其他所有的安卓系统。必须将依赖项替换为它们的 AndroidX 对应项。
之后:
flutter upgrade
flutter pub get
flutter clean
flutter build apk --release
如果问题仍然存在:
1) Restart the computer, cross your fingers.
【讨论】:
谢谢。主要问题是compileSdkVersion 31
。我从 30 更改为 31 以解决我的问题
我交叉手指,它成功了,谢谢以上是关于两个包在颤振中使用两个不同的 compileSdkVersion的主要内容,如果未能解决你的问题,请参考以下文章
Azure 应用服务App Service 部署txt静态文件和Jar包在不同目录中的解决办法