flutter-geolocator
flutter-geolocator copied to clipboard
[Question]:
Please check the following before submitting a new issue.
- [X] I have searched the existing issues.
- [X] I have carefully read the documentation.
Please select for which platform(s) you need help
- [X] Android
- [ ] iOS
- [ ] Linux
- [ ] macOS
- [ ] Web
- [ ] Windows
Your question
Hi
I tried to add geolocator to an existing project, but the compilation fails on android with the following error :
/Users/xxx/.pub-cache/hosted/pub.dev/geolocator_android-4.5.2/android/src/main/java/com/baseflow/geolocator/location/FusedLocationClient.java:29: error: cannot find symbol import com.google.android.gms.location.Priority; ^ symbol: class Priority location: package com.google.android.gms.location /Users/xxx/.pub-cache/hosted/pub.dev/geolocator_android-4.5.2/android/src/main/java/com/baseflow/geolocator/location/FusedLocationClient.java:91: error: cannot find symbol LocationRequest.Builder builder = new LocationRequest.Builder(0); ^ symbol: class Builder location: class LocationRequest
And several related errors of the same type I tried to clean the pub cache, event the gradle cache, but I keep getting this error and can't find much about it on the internet.
Some relevant configurations items :
- compileSdkVersion 34
- jvmTarget = '17'
- sourceCompatibility JavaVersion.VERSION_1_8
- minSdkVersion 26
- classpath 'com.android.tools.build:gradle:7.1.2'
- classpath 'com.google.gms:google-services:4.3.10'
Any help will be appreciated ! Thanks
Julien
Version
11.0.0
Dear @galvin59,
Can you add the output of flutter doctor -v to this issue?
Kind regards,
Hi @galvin59,
The types mentioned are declared as part of the com.google.android.gms:play-services-location:21.1.0 library. Normally when depending on the geolocator plugin this Android library should automatically be added to your project. However in certain cases (usually involving specific configuration in the build.gradle file) this library is excluded from the project.
Could you try adding the following to the dependencies section in your android/app/build.gradle file:
implementation 'com.google.android.gms:play-services-location:21.1.0'
If this doesn't work, please provide the output of the flutter doctor -v command (as mentioned by @TimHoogstrate ) and if possible your build.gradle file.
Please let us know.
Thanks for your help adding implementation 'com.google.android.gms:play-services-location:21.1.0' did not help unfortunately
The flutter doctor -v output :
[✓] Flutter (Channel stable, 3.19.0, on macOS 14.2.1 23C71 darwin-arm64, locale fr-FR) • Flutter version 3.19.0 on channel stable at /Users/Julien/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision bae5e49bc2 (6 days ago), 2024-02-13 17:46:18 -0800 • Engine revision 04817c99c9 • Dart version 3.3.0 • DevTools version 2.31.1
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/Julien/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) • All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.2) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15C500b • CocoaPods version 1.13.0
[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2023.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
[✓] VS Code (version 1.86.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.82.0
[✓] Connected device (3 available) • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 13 (API 33) (emulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.2.1 23C71 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 121.0.6167.184 ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac. The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] Network resources • All expected network resources are available.
• No issues found!
build.gradle
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'
}
def dartEnvironmentVariables = [
DEFINEEXAMPLE_APP_NAME: 'xxx-unknown',
DEFINEEXAMPLE_APP_SUFFIX: ''
];
if (project.hasProperty('dart-defines')) {
dartEnvironmentVariables = dartEnvironmentVariables + project.property('dart-defines')
.split(',')
.collectEntries { entry ->
def pair = new String(entry.decodeBase64(), 'UTF-8').split('=')
[(pair.first()): pair.last()]
}
}
apply plugin: 'com.android.application'
// START: FlutterFire Configuration
apply plugin: 'com.google.gms.google-services'
// END: FlutterFire Configuration
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
}
compileSdkVersion 34
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '17'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
applicationId "com.xxx.app.truck"
applicationIdSuffix dartEnvironmentVariables.DEFINEEXAMPLE_APP_SUFFIX
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
resValue "string", "app_name", dartEnvironmentVariables.DEFINEEXAMPLE_APP_NAME
}
signingConfigs {
release {
if (System.getenv()["CI"]) { // CI=true is exported by Codemagic
storeFile file(System.getenv()["CM_KEYSTORE_PATH"])
storePassword System.getenv()["CM_KEYSTORE_PASSWORD"]
keyAlias System.getenv()["CM_KEY_ALIAS"]
keyPassword System.getenv()["CM_KEY_PASSWORD"]
} else {
storeFile file('/Users/xxx/Documents/xxx/apps/keystore/keystore')
storePassword 'phoceis'
keyAlias = 'compile'
keyPassword 'phoceis'
}
}
}
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.release
ndk {
debugSymbolLevel 'FULL'
}
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.android.gms:play-services-location:21.1.0'q
implementation files('libs/commons-io-2.2.jar')
implementation files('libs/commons-lang3-3.4.jar')
implementation files('libs/commons-net-3.1.jar')
implementation files('libs/commons-validator-1.4.0.jar')
implementation files('libs/core-1.53.0.0.jar')
implementation files('libs/httpcore-4.3.1.jar')
implementation files('libs/httpmime-4.3.2.jar')
implementation files('libs/jackson-annotations-2.2.3.jar')
implementation files('libs/jackson-core-2.2.3.jar')
implementation files('libs/jackson-databind-2.2.3.jar')
implementation files('libs/opencsv-2.2.jar')
implementation files('libs/pkix-1.53.0.0.jar')
implementation files('libs/prov-1.53.0.0.jar')
implementation files('libs/snmp6_1z.jar')
implementation files('libs/ZSDK_ANDROID_API.jar')
// implementation "com.google.android.gms:play-services-location:21.0.1"
}
I am also facing similar issue.
Could any other version set help us to resolve this issue?
I did a dependency override for geolocation android and it worked.
geolocator_android: 4.2.0
But if I add this in dependency override, build issue has been resolved but the map is not loading
did a dependency override for geolocation android and it worked.
geolocator_android: 4.2.0
I ran into the same error, and this worked, thanks! I have successfully reproduced the problem with the newest version of flutter:
- flutter create a new project
- flutter pub add geolocator
- flutter pub get
- flutter build apk Below are my error output:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkReleaseDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
> Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)
Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk7-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10)
Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations$ReflectSdkVersion found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk7-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10)
Duplicate class kotlin.internal.jdk8.JDK8PlatformImplementations found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)
Duplicate class kotlin.internal.jdk8.JDK8PlatformImplementations$ReflectSdkVersion found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)
Duplicate class kotlin.io.path.ExperimentalPathApi found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk7-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10)
Duplicate class kotlin.io.path.PathRelativizer found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk7-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10)
Duplicate class kotlin.io.path.PathsKt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk7-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10)
Duplicate class kotlin.io.path.PathsKt__PathReadWriteKt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk7-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10)
Duplicate class kotlin.io.path.PathsKt__PathUtilsKt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk7-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10)
Duplicate class kotlin.jdk7.AutoCloseableKt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk7-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10)
Duplicate class kotlin.jvm.jdk8.JvmRepeatableKt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)
Duplicate class kotlin.jvm.optionals.OptionalsKt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)
Duplicate class kotlin.random.jdk8.PlatformThreadLocalRandom found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)
Duplicate class kotlin.streams.jdk8.StreamsKt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)
Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$1 found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)
Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$2 found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)
Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$3 found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)
Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$4 found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)
Duplicate class kotlin.text.jdk8.RegexExtensionsJDK8Kt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)
Duplicate class kotlin.time.jdk8.DurationConversionsJDK8Kt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)
Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.
* 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 12s
Could you provide more information on how you solve this issue because I added geolocator and geolocator_android and I'm still failing to build android apk
I solve the problem by editing android/settings.gradle
id "org.jetbrains.kotlin.android" version "1.9.22" apply false //1.9.22 is the latest kotlin version
Hi @galvin59,
During a deeper dive we realized that a recents upgrade of the com.google.android.gms:play-services-location (from 21.0.1 to 21.1.0) also required an update of the Kotlin tooling. Something Google hasn't mentioned in their release notes unfortunately.
This means that for Flutter projects that use Kotlin (which is the default at the moment) as their Android native language some extra steps need to happen (also mentioned by @ethicnology).
Although the error is different from the error you report, I would appreciate it if you could give it a try. The steps to update the Kotlin version used in your project are (original comment):
- Open the file
android/settings.gradle - Change the version number from
"1.7.10"to"1.9.20"of theorg.jetbrains.kotlin.androiddependency insettings.gradlefile:
Before:
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
}
After:
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
id "org.jetbrains.kotlin.android" version "1.9.20" apply false
}
- Go to
android/build.gradleand added the following block of code at the very top of thebuild.gradlefile:
buildscript {
ext.kotlin_version = '1.5.31'
}
- Run the following commands from the project directory:
cd android
./gradlew clean
cd ..
flutter clean
flutter pub get
- Run the application to see if the problem is resolved.
@Harsh-4002, please have a look at issue #1441. I contains details instructions (same as my comment above yours) on how to resolve it.
I will delete your question as it pollutes the question of the original poster.
@galvin59, we have recently reverted the upgrade of the com.google.android.gms:play-services-location library from version 21.0.1 to 21.1.0.
As of version 4.5.3 of the geolocator_android package the Geolocator makes use of version 21.0.1 the com.google.android.gms:play-services-location library again which should resolve the issue you have reported.