在颤振中为Android构建时“错误:找不到符号”
Posted
技术标签:
【中文标题】在颤振中为Android构建时“错误:找不到符号”【英文标题】:"error: cannot find symbol" when building for Android in flutter 【发布时间】:2021-05-24 02:18:48 【问题描述】:在我的颤振应用程序中尝试为 android 构建时,我不断收到此错误。这一切都是在我添加firebase messaging version 7.0.3
时发生的。即使将其删除后,我仍然存在此问题。
/Users/bright/Desktop/flutter_apps/rush_user_app/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java:20: error: cannot find symbol
flutterEngine.getPlugins().add(new io.flutter.plugins.flutter_plugin_android_lifecycle.FlutterAndroidLifecyclePlugin());
^
symbol: class FlutterAndroidLifecyclePlugin
location: package io.flutter.plugins.flutter_plugin_android_lifecycle
/Users/bright/Desktop/flutter_apps/rush_user_app/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java:24: error: cannot find symbol
flutterEngine.getPlugins().add(new io.flutter.plugins.googlemaps.GoogleMapsPlugin());
^
symbol: class GoogleMapsPlugin
location: package io.flutter.plugins.googlemaps
/Users/bright/Desktop/flutter_apps/rush_user_app/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java:25: error: cannot find symbol
flutterEngine.getPlugins().add(new io.flutter.plugins.googlesignin.GoogleSignInPlugin());
^
symbol: class GoogleSignInPlugin
location: package io.flutter.plugins.googlesignin
/Users/bright/Desktop/flutter_apps/rush_user_app/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java:26: error: cannot find symbol
flutterEngine.getPlugins().add(new io.flutter.plugins.imagepicker.ImagePickerPlugin());
^
symbol: class ImagePickerPlugin
location: package io.flutter.plugins.imagepicker
/Users/bright/Desktop/flutter_apps/rush_user_app/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java:30: error: cannot find symbol
flutterEngine.getPlugins().add(new io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin());
^
symbol: class SharedPreferencesPlugin
location: package io.flutter.plugins.sharedpreferences
5 errors
Running Gradle task 'assembleDebug'... Done 102.9s
Exception: Gradle task assembleDebug failed with exit code 1
这是我的GeneratedPluginRegistrant.java
package io.flutter.plugins;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry;
/**
* Generated file. Do not edit.
* This file is generated by the Flutter tool based on the
* plugins that support the Android platform.
*/
@Keep
public final class GeneratedPluginRegistrant
public static void registerWith(@NonNull FlutterEngine flutterEngine)
ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine);
flutterEngine.getPlugins().add(new io.flutter.plugins.flutter_plugin_android_lifecycle.FlutterAndroidLifecyclePlugin());
flutterEngine.getPlugins().add(new io.github.ponnamkarthik.toast.fluttertoast.FlutterToastPlugin());
flutterEngine.getPlugins().add(new com.baseflow.geolocator.GeolocatorPlugin());
flutterEngine.getPlugins().add(new com.baseflow.googleapiavailability.GoogleApiAvailabilityPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.googlemaps.GoogleMapsPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.googlesignin.GoogleSignInPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.imagepicker.ImagePickerPlugin());
com.codeheadlabs.libphonenumber.LibphonenumberPlugin.registerWith(shimPluginRegistry.registrarFor("com.codeheadlabs.libphonenumber.LibphonenumberPlugin"));
flutterEngine.getPlugins().add(new com.lyokone.location.LocationPlugin());
flutterEngine.getPlugins().add(new com.baseflow.location_permissions.LocationPermissionsPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin());
flutterEngine.getPlugins().add(new com.aboutyou.dart_packages.sign_in_with_apple.SignInWithApplePlugin());
这是我的 android 文件夹结构
我曾尝试用谷歌搜索解决方案,但我没有找到任何与我的问题相似的建议。这是我的颤振医生输出
[✓] Flutter (Channel stable, 1.22.5, on Mac OS X 10.15.4 19E287 darwin-x64, locale en-KE)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for ios and macOS (Xcode 11.5)
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.53.2)
[✓] Connected device (1 available)
! Doctor found issues in 1 category.
这是我的依赖项
dependencies:
flutter:
sdk: flutter
carousel_slider: ^2.3.1
intl_phone_number_input: ^0.5.2+2
pinput: ^0.2.6
cupertino_icons: ^1.0.0
dotted_border: ^1.0.6
dotted_line: ^2.0.2
date_field: ^1.0.5
intl: ^0.16.1
image_picker: ^0.6.7+22
flutter_rating_bar: ^3.2.0+1
signature: ^3.2.0
scrollable_positioned_list: ^0.1.9
http: ^0.12.1
shared_preferences: ^0.5.12+4
provider: null
google_maps_flutter: ^1.2.0
location: ^3.2.4
geolocator: ^5.3.2+2
shimmer: ^1.1.2
flutter_google_places: ^0.2.6
google_maps_webservice: ^0.0.19
fluttertoast: ^7.1.6
flutter_polyline_points: ^0.2.4
uuid: null
google_sign_in: ^4.5.9
sign_in_with_apple: ^2.5.4
firebase_messaging: ^7.0.3
我已尝试迁移到新项目并仅传输 lib、ios 和 pubspec.yaml,但错误仍然存在。 请帮忙!
【问题讨论】:
【参考方案1】:经过一番汗水的斗争,我决定从我得到的无数搜索结果中尝试一个随机的解决方案,瞧
flutter pub cache repair
【讨论】:
【参考方案2】:对我来说,我总是尝试清理颤振构建:
flutter clean
【讨论】:
【参考方案3】:花了一个小时进行随机修复。最后运行“flutter clean”并重建工作
【讨论】:
【参考方案4】:就我而言
我的错误:->
C:\Users\Niket\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.3.0\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
解决方案:
第 1 步:转到 android/app/src/build.gradle
第 2 步:将 compileSdkVersion 更新为您的虚拟设备版本
android
compileSdkVersion 31 //before its 30
...
【讨论】:
【参考方案5】:快跑
flutter clean
flutter build
我有同样的问题,这个有帮助。
【讨论】:
以上是关于在颤振中为Android构建时“错误:找不到符号”的主要内容,如果未能解决你的问题,请参考以下文章
在 android 中使用 MVVM 设计模式时出错找不到符号类 ViewModel
构建 Gradle 时出现问题(无法创建任务 ':path_provider_android:generateDebugUnitTestConfig')。在颤振中为 android