skip to Main Content

I am upgrading Flutter to 3.19.0 and I am having problem with Android setup. According to Flutter’s breaking changes, the Android setup should look different now. I think I followed all the instructions and have the following gradle files:

android/settings.gradle:

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }
    settings.ext.flutterSdkPath = flutterSdkPath()

    includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

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
    id "com.google.gms.google-services" version "4.4.0" apply false
    id "com.google.firebase.crashlytics" version "2.9.9" apply false
}

include ":app"

android/build.gradle:

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

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

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

android/app/build.gradle:

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    id "com.google.gms.google-services"
    id "com.google.firebase.crashlytics"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('dev.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

def prodKeystoreProperties = new Properties()
def prodKeystorePropertiesFile = rootProject.file('....properties')
if (prodKeystorePropertiesFile.exists()) {
    prodKeystoreProperties.load(new FileInputStream(prodKeystorePropertiesFile))
}

android {
    compileSdkVersion 34
    ndkVersion "25.1.8937393"

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
        checkReleaseBuilds false
    }

    defaultConfig {
        applicationId "..."
        minSdkVersion 25
        targetSdkVersion 34
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
        testInstrumentationRunner "pl.leancode.patrol.PatrolJUnitRunner"
        ndk {
            // Filter for architectures supported by Flutter.
            abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64'
        }
    }

    signingConfigs {
        ...
    }

    flavorDimensions "app"

    productFlavors {
        ...
    }

    buildTypes {
        ...
    }

    testOptions {
        execution "ANDROIDX_TEST_ORCHESTRATOR"
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10"
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.browser:browser:1.3.0'
    androidTestUtil "androidx.test:orchestrator:1.4.2"
}

Unfortunately, when I run the app, the Firebase package doesn’t initialize properly with error:

PlatformException(null-error, Host platform returned null value for non-null return value., null, null).

And the app stays stuck at splash screen.

I’ve seen many solutions to that problem but they use old buildscript approach to android dependencies, I haven’t found any solution to this using the new approach.

Any help would be much appreciated 🙏

2

Answers


  1. Try to downgrade from 4.4.0 to 4.3.15 or 4.3.8

    id 'com.google.gms.google-services' version '4.3.15' apply false

    Login or Signup to reply.
  2. Salah eddine Naoushi your answer is correct. thank you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search