尝试在物理设备上运行我的 flutter 应用程序,但一直显示以下错误:
Launching lib/main.dart on Pixel 3a in debug mode...
Running Gradle task 'assembleDebug'...
Note: /Users/jasonlloyd/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/google_api_availability-2.0.4/android/src/main/java/com/baseflow/googleapiavailability/GoogleApiAvailabilityPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/jasonlloyd/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-1.3.0/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebaseCorePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/jasonlloyd/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-2.2.2/android/src/main/java/io/flutter/plugins/firebase/firestore/FlutterFirebaseFirestorePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/jasonlloyd/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-2.2.2/android/src/main/java/io/flutter/plugins/firebase/firestore/streamhandler/TransactionStreamHandler.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
/Users/jasonlloyd/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/location_permissions-3.0.0+1/android/src/main/java/com/baseflow/location_permissions/LocationPermissionsPlugin.java:284: error: cannot find symbol
|| (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && permission.equals(Manifest.permission.ACCESS_BACKGROUND_LOCATION));
^
symbol: variable Q
location: class VERSION_CODES
/Users/jasonlloyd/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/location_permissions-3.0.0+1/android/src/main/java/com/baseflow/location_permissions/LocationPermissionsPlugin.java:284: error: cannot find symbol
|| (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && permission.equals(Manifest.permission.ACCESS_BACKGROUND_LOCATION));
^
symbol: variable ACCESS_BACKGROUND_LOCATION
location: class permission
/Users/jasonlloyd/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/location_permissions-3.0.0+1/android/src/main/java/com/baseflow/location_permissions/LocationPermissionsPlugin.java:308: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
^
symbol: variable Q
location: class VERSION_CODES
/Users/jasonlloyd/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/location_permissions-3.0.0+1/android/src/main/java/com/baseflow/location_permissions/LocationPermissionsPlugin.java:309: error: cannot find symbol
names.add(Manifest.permission.ACCESS_BACKGROUND_LOCATION);
^
symbol: variable ACCESS_BACKGROUND_LOCATION
location: class permission
/Users/jasonlloyd/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/location_permissions-3.0.0+1/android/src/main/java/com/baseflow/location_permissions/LocationPermissionsPlugin.java:330: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && hasPermissionInManifest(Manifest.permission.ACCESS_BACKGROUND_LOCATION, context)) {
^
symbol: variable Q
location: class VERSION_CODES
/Users/jasonlloyd/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/location_permissions-3.0.0+1/android/src/main/java/com/baseflow/location_permissions/LocationPermissionsPlugin.java:330: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && hasPermissionInManifest(Manifest.permission.ACCESS_BACKGROUND_LOCATION, context)) {
^
symbol: variable ACCESS_BACKGROUND_LOCATION
location: class permission
/Users/jasonlloyd/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/location_permissions-3.0.0+1/android/src/main/java/com/baseflow/location_permissions/LocationPermissionsPlugin.java:331: error: cannot find symbol
permissionNames.add(Manifest.permission.ACCESS_BACKGROUND_LOCATION);
^
symbol: variable ACCESS_BACKGROUND_LOCATION
location: class permission
/Users/jasonlloyd/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/location_permissions-3.0.0+1/android/src/main/java/com/baseflow/location_permissions/LocationPermissionsPlugin.java:372: error: cannot find symbol
return locationManager.isLocationEnabled();
^
symbol: method isLocationEnabled()
location: variable locationManager of type LocationManager
Note: /Users/jasonlloyd/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/location_permissions-3.0.0+1/android/src/main/java/com/baseflow/location_permissions/LocationPermissionsPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
8 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':location_permissions: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 10s
Exception: Gradle task assembleDebug failed with exit code 1
我已尝试遵循此处的建议:Execution Failed for task :app:compileDebugJavaWithJavac in Android Studio 但仍然无效。有什么想法吗?
答案 0 :(得分:0)
您是否允许在 Manifest 中使用后台位置?
<manifest ... >
<!-- Required only when requesting background location access on
Android 10 (API level 29) and higher. -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
</manifest>
答案 1 :(得分:0)
解决了!我只需要将 pubspec.yaml 中的一个依赖项更新到最新版本,特别是将位置 pacakage 更改为 location: ^4.3.0
。希望这对未来的人有所帮助。