简体   繁体   English

在 flutter 中构建 Android 时出现“错误:找不到符号”

[英]"error: cannot find symbol" when building for Android in flutter

I keep getting this error when trying to build for android in my flutter app.在我的 flutter 应用程序中尝试构建 android 时,我不断收到此错误。 This all happened when i added firebase messaging version 7.0.3 .这一切都发生在我添加firebase messaging version 7.0.3时。 Even after removing it i got this issue persisting.即使在删除它之后,这个问题仍然存在。

/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

Here is my GeneratedPluginRegistrant.java这是我的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());
  }
}

Here is my android folder structure这是我的 android 文件夹结构

Android 文件夹屏幕截图

I have tried to google for solutions but i have not found any suggestions that were similar to my issue.我曾尝试在谷歌上搜索解决方案,但没有找到与我的问题类似的任何建议。 Here is my flutter doctor output这是我的 flutter 医生 output

[✓] 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.

Here are my dependencies这是我的依赖项

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

I have tried migrating to a new project and transffering the lib, ios and pubspec.yaml only but the error is still there.我尝试迁移到一个新项目并仅传输 lib、ios 和 pubspec.yaml,但错误仍然存在。 Please help!请帮忙!

After a sweaty struggle i decided to try a random solution out of the countless search results i got and voila经过一番汗流浃背的斗争,我决定从我得到的无数搜索结果中尝试一个随机的解决方案,瞧

flutter pub cache repair

For me I always try cleaning flutter build:对我来说,我总是尝试清理 flutter 构建:

flutter clean

Just run赶紧跑

flutter clean
flutter build

I had same problem, this one helps.我有同样的问题,这个有帮助。

Spent an hour in random fixes.花了一个小时进行随机修复。 Finally running 'flutter clean' and rebuilding worked最后运行'flutter clean'并重建工作

In my case就我而言

My Error: ->我的错误:->

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

Solution:解决方案:

Step 1: Goto android/app/src/build.gradle第 1 步:转到 android/app/src/build.gradle

Step 2: Update compileSdkVersion to your virtual device version第 2 步:将 compileSdkVersion 更新为您的虚拟设备版本

android {
    compileSdkVersion 31 //before its 30 
    ...
}

Issue fixed for my by running following two commands通过运行以下两个命令为我修复了问题

flutter clean
flutter pub get

I have tried all options for this我已经为此尝试了所有选项

  1. flutter clean
  2. flutter build apk

Even after this i could not find my solution.即使在此之后,我也找不到我的解决方案。 finally i ratified my mistake that i have not added最后我批准了我没有添加的错误

key.properties file in project项目中的key.properties文件

You must have detached a plugin from pubspec.yml cache needs to be clear您必须从 pubspec.yml 缓存中分离插件需要清除

flutter clean
flutter pub cache repair
flutter pub get

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用新类为 Android 构建 Chromium 时出现“错误:找不到符号” - "error: cannot find symbol" when building Chromium for Android with new classes [错误]:使用 maven 和 lombok 构建时找不到符号变量日志 - [ERROR]: cannot find symbol variable log when building with maven and lombok 错误 java:使用 JHipster 构建时找不到符号 - ERROR java: cannot find symbol when building with JHipster Android错误找不到符号 - Android error cannot find symbol 使用Gradle编译Android项目时出现“错误:找不到符号” - “Error: cannot find symbol” when compiling Android project using Gradle 尝试访问android项目资源时出现“无法查找符号”错误 - “Cannot Find Symbol” error when trying to access android project resources 构建Mopub SDK时,找不到符号:类org.fest.assertions.api.ANDROID - When building mopub sdk, cannot find symbol: class org.fest.assertions.api.ANDROID 为React-Native构建Android模块时找不到符号getCurrentActivity - Cannot find symbol getCurrentActivity when building an Android module for React-Native 如何在构建时修复“找不到符号”错误? - How do I fix the “cannot find symbol” error while building? Android中的错误:找不到符号方法 - Error in Android: Cannot find symbol method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM