Hi Everyone,
I’m currently building a Flutter app (everything works fine in debug mode), and I’m now at the point where I want to generate a release APK. Most things are already coded, and the app starts correctly inside Android Studio and on emulators. I can start the Debug App and the Release App. All works fine.
However, I’ve been running into a persistent Gradle build error related to geolocator_android
— and despite numerous attempts to fix it, the issue keeps coming back.
The Error
The supplied phased action failed with an exception.
A problem occurred configuring project ':geolocator_android'.
Build file 'C:\\Users\\Dennis\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\geolocator_android-4.6.2\\android\\build.gradle' line: 5
An exception occurred applying plugin request [id: 'dev.flutter.flutter-gradle-plugin']
> Failed to apply plugin 'dev.flutter.flutter-gradle-plugin'.
> Cannot add task 'generateLockfiles' as a task with that name already exists.
This error previously disappeared after I upgraded Flutter to 3.29.2
, but has now reappeared even though no major changes were made since.
🔧 Environment
[✓] Flutter (Channel stable, 3.29.2)
[✓] Android Studio (2024.1)
[✓] Android SDK 35.0.0
[✓] Kotlin 2.1.0
[✓] Gradle 8.3 via wrapper
[✓] Java 17.0.12
[✓] Windows 11 Pro 64-bit (24H2, 2009)
What I’ve Already Tried
Cleaning
flutter clean
rm pubspec.lock
rm -rf .dart_tool/ .flutter-plugins* build/
Also manually deleted:
.gradle/
Pub/Cache/hosted/pub.dev/geolocator_android-4.6.2
Updating Flutter and Dart
- Upgraded to Flutter
3.29.2
- Ran
flutter upgrade
,flutter doctor
— no issues
pubspec.yaml (current)
dependencies:
flutter:
sdk: flutter
geolocator: ^13.0.4
firebase_core: ^3.6.0
firebase_auth: ^5.3.1
firebase_messaging: ^15.1.3
firebase_storage: ^12.3.4
firebase_app_check: ^0.3.1
cloud_firestore: ^5.4.4
flutter_local_notifications: ^19.0.0
google_fonts: ^6.2.1
http: ^1.2.2
image_picker: ^1.1.2
intl: ^0.19.0
logger: ^2.4.0
logging: ^1.0.2
flutter_localizations:
sdk: flutter
Kotlin/Gradle Setup
distributionUrl=https://services.gradle.org/distributions/gradle-8.3-all.zip
ext.kotlin_version = '2.1.0'
classpath 'com.android.tools.build:gradle:8.8.0'
The Root of the Problem
Even though I am using geolocator: ^13.0.4
, which should pull in a modern implementation, the pubspec.lock
always resolves to:
geolocator_android: 4.6.2
But:
flutter pub get
shows:
geolocator_android 4.6.2 (5.0.1 available)
This Version i cant install.
→ Confirms it pulls 4.6.2
as a transitive dependency, even with latest geolocator
.
My Questions
- Why is geolocator 13.0.4 still pulling in geolocator_android 4.6.2, which appears to break with modern Gradle/Kotlin setups?
- Why is the flutter-gradle-plugin trying to register
generateLockfiles
multiple times? - Is this a known issue in geolocator_android, or in the Gradle plugin itself?
- Is there a workaround or patch to avoid this issue?
How can i get Rid of this Issue?
buildscript {
ext.kotlin_version = '2.1.0'
repositories {
google()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:8.8.0'
// Füge das Google Services Plugin hinzu
classpath 'com.google.gms:google-services:4.4.2' // Verwende eine aktuelle Version, wenn verfügbar
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.1.0" apply false
id "org.jetbrains.kotlin.android" version "2.1.0" apply false
}
include ":app"
dependency_overrides:
geolocator_android: ^5.0.1
Also didnt work
Do you have any Ideas?