Search code examples
androidgoogle-mapsandroid-studio-flamingo

Android Studio Flamingo android lifecycle issue with Android Devices, after adding Google Maps plugin


Trying to build a cross platform connected device Google Maps enabled App using flutter framework on Android Studio Flaming 2022.2.1 Patch 2, without success. The flutter run works seemlessly until device dependency google_maps_flutter: ^2.4.0 is used under pubspec.yaml. Also after added this

  flutter_plugin_android_lifecycle: ^2.0.15

the problem still here.

iOS build is ok, also Android was perfect before Google Maps was added.

Please note that I have a strage issue, with my system PATH. Doctor tell me that I have an Issue, but the PATH is perfect and built for iOS is ok. I will write another post for this strange issue.

Coming back to this question, I searched for solutions over the web, but unsuccessfully, so this is my dev environment, hoping someone can help me.

pubspec.yaml

dependencies:
  http: ^0.13.6
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  # Google Area
  google_maps_flutter: ^2.4.0
  google_fonts: ^4.0.4
  flutter_plugin_android_lifecycle: ^2.0.15

flutter doctor -v

[!] Flutter (Channel stable, 3.10.6, on macOS 13.4.1 22F770820d darwin-x64, locale it-IT)
    • Flutter version 3.10.6 on channel stable at /Users/maxmac/Development/flutter
    ! Warning: `flutter` on your path resolves to /Users/MaxMac/Development/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/maxmac/Development/flutter.
      Consider adding /Users/maxmac/Development/flutter/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/MaxMac/Development/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/maxmac/Development/flutter. Consider
      adding /Users/maxmac/Development/flutter/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f468f3366c (3 weeks ago), 2023-07-12 15:19:05 -0700
    • Engine revision cdbeda788a
    • Dart version 3.0.6
    • DevTools version 2.23.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/maxmac/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.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • 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.6+0-17.0.6b802.4-9586694)

[✓] Connected device (4 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554                        • android-x64    • Android 14 (API 34) (emulator)
    • iPhone 14 (mobile)           • 387BA0EA-FD06-4ABE-82E3-40FAE3AEBEDE • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)              • macos                                • darwin-x64     • macOS 13.4.1 22F770820d darwin-x64
    • Chrome (web)                 • chrome                               • web-javascript • Google Chrome 115.0.5790.170

[✓] Network resources
    • All expected network resources are available.

android/build.gradle. As you can see I have added both [ mavenCentral() ] and [ maven { url "https://maven.google.com" } ]

buildscript {
    ext.kotlin_version = '1.9.0'
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url "https://maven.google.com" }

    }

    dependencies {
        classpath 'com.android.tools.build:gradle:8.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        //implementation 'com.google.gms:google-services:3.0.0'

    }

}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url "https://maven.google.com" }

    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

This is Adroid Project Structure settings

The following error are generated (only for Android build)

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':flutter_plugin_android_lifecycle'.
> Could not resolve all files for configuration ':flutter_plugin_android_lifecycle:classpath'.
   > Could not find com.android.tools.build:gradle:4.3.1.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.3.1/gradle-4.3.1.pom
       - https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/4.3.1/gradle-4.3.1.pom
     Required by:
         project :flutter_plugin_android_lifecycle
> Failed to notify project evaluation listener.
   > Could not get unknown property 'android' for project ':flutter_plugin_android_lifecycle' of type org.gradle.api.Project.
   > Could not get unknown property 'android' for project ':flutter_plugin_android_lifecycle' of type org.gradle.api.Project.

Trying to do some additional setting, for example from here maps template issue, and again nothing.


Solution

  • Near to become really crazy, days trying to rebuild and change setup of my dev environment, and also after post the issue on github without any answer, I have found the issue by myself. This is definitely a bug on source code of the plugin flutter_plugin_android_lifecycle-2.0.15.

    I have found the bug on its source code, in its build.gradle. You have to go here, for MAC OS: /Users/<your name>/.pub-cache/hosted/pub.dev/flutter_plugin_android_lifecycle-2.0.15/android

    The guild.gradle, have this wrong dependence

            classpath 'com.android.tools.build:gradle:4.3.1'
    

    I have changed it in

            classpath 'com.android.tools.build:gradle:7.0.2'
    

    ... and after rebuilt, the problem is SOLVED. I will try also with

            classpath 'com.android.tools.build:gradle:7.2.1'
    

    Because the previous release, in the same pub.dev directory, flutter_plugin_android_lifecycle-2.0.8, has this dependence.

    Now my pubspec.yaml, for Google Maps has got only this dependencies:

    google_maps_flutter: ^2.4.0
    

    Hoping this can help you.