I updated a 2 year old flutter-project and get the following error at debugging. I need help. I tried to fix the error for 4 days.
Launching lib/main.dart on sdk gphone x86 in debug mode…
/Users/michael/.pub-cache/hosted/pub.dev/firebase_core-2.24.2/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebaseCoreRegistrar.java:19:
error: cannot find symbol
LibraryVersionComponent.create(BuildConfig.LIBRARY_NAME, BuildConfig.LIBRARY_VERSION));
^
symbol: variable BuildConfig
location: class FlutterFirebaseCoreRegistrar
Another new created flutter project could be run. I tried with gradle 7.5 and Gradle 8. Both show the mentioned error.
My Flutter doctor
[✓] Flutter (Channel stable, 3.16.1, on macOS 14.1.1 23B81 darwin-x64, locale de-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.84.2)
[✓] VS Code (version 1.48.2)
My build.gradle (project)
buildscript {
// 202306 BEFORE '1.7.10' AFTER '1.9.21'
ext.kotlin_version = '1.9.21'
repositories {
google()
jcenter()
}
dependencies {
// classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:8.1.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// 202306 BEFORE 4.3.10 AFTER 4.4.0
classpath 'com.google.gms:google-services:4.4.0'
}
}
// 202306
subprojects{
afterEvaluate {
android {
namespace 'com.example.camflo'
}
} }
allprojects {
repositories {
google()
jcenter()
} }
rootProject.buildDir = '../build' subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects {
project.evaluationDependsOn(':app') }
tasks.register("clean", Delete) {
delete rootProject.buildDir }
My build.gradle app:
def localProperties = new Properties() def localPropertiesFile =
rootProject.file('local.properties') if (localPropertiesFile.exists())
{
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
} }
def flutterRoot = localProperties.getProperty('flutter.sdk') if
(flutterRoot == null) {
throw GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") }
def flutterVersionCode =
localProperties.getProperty('flutter.versionCode') if
(flutterVersionCode == null) {
flutterVersionCode = '1' }
def flutterVersionName =
localProperties.getProperty('flutter.versionName') if
(flutterVersionName == null) {
flutterVersionName = '1.0' }
apply plugin: 'com.android.application' apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services' apply from:
"$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
// compileSdkVersion 28
compileSdkVersion 33
namespace = "com.example.camflo"
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
// 202306 added buildFeatures and buildConfig with no change of error
// buildFeatures {
// buildConfig = true
// }
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.camflo.app"
minSdkVersion 29
// minSdkVersion 30
// targetSdkVersion 28
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
lint {
disable 'InvalidPackage'
} }
flutter {
source '../..' }
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-analytics:17.5.0' }
My dependencies:
environment:
sdk: ">=2.12.0 <=4.0.0"
dependency_overrides:
package_info_plus: ^4.2.0
http: ^1.1.2
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
shared_preferences: "2.2.2"
platform: ^3.1.3
firebase_core: ^2.24.2
firebase_analytics: ^10.7.1
firebase_auth: ^4.14.1
firebase_storage: ^11.5.2
cloud_firestore: ^4.13.2
provider: ^6.1.1
image_picker: ^1.0.4
timeago: ^3.6.0
flutter_spinkit: ^5.2.0
geolocator: ^10.1.0
uuid: ^4.2.1
image: ^4.1.3
animator: ^3.3.0
http: ^0.13.0
path_provider: ^2.0.1
firebase_messaging: ^14.7.5
cached_network_image: ^3.3.0
photo_view: ^0.14.0
preload_page_view: ^0.2.0
flutter_google_places_hoc081098: ^1.2.0
material_design_icons_flutter: 7.0.7296
google_mobile_ads: ^3.1.0
google_mobile_ads: ^4.0.0
google_maps_webservice: ^0.0.20-nullsafety.2
firebase_dynamic_links: ^5.4.5
cupertino_icons: ^1.0.6
dev_dependencies:
flutter_test:
sdk: flutter
2
Answers
for 1st try i think error is most likely a mismatch between the flutter and Android versions used in the project. the buildConfig symbol is generated by the Android build system, and if the flutter and android versions are not compatible, the symbol may not be available.
so pleas do the following .
1.run –
flutter upgrade
2.Update the Android SDK- in android studio go to the SDK Manager, then installing any available updates.
a. inside project-level build.gradle file:
Change the ext.kotlin_version to a compatible version for that you can check the latest Kotlin version on the Kotlin website.
then
Change the classpath ‘com.android.tools.build:gradle:8.1.4’ to a compatible version. You can check the latest Android Gradle Plugin version on the Android Gradle Plugin Release Notes page.
b. in-side the app-level build.gradle file:
Change the compileSdkVersion to a compatible version. You can check the latest Android SDK version in the Android Studio SDK Manager.
then change the minSdkVersion and targetSdkVersion to compatible versions. Make sure they are within the range supported by your Flutter version.
after going all the above try run the following command to sync the project with the updated configurations
hope you use version control in you project .so that you can always rollback
let me know any
try removing dependency
in
check the if imports are correct
open android folder in android studio to identify problem in config files