skip to Main Content

I have seen a lot of these issues about the error below:
"[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(null-error, Host platform returned null value for non-null return value., null, null)" but all the solutions are not solving my problem
I have followed all the instructions ditto, adding dependencies and what not. my build.gradles are ok but when I run I still get the error. this worked for me a month ago but now I don;t know what is happening this month.

Launching libmain.dart on AOSP on IA Emulator in debug mode...
Running Gradle task 'assembleDebug'...
Parameter format not correct -
√  Built buildappoutputsflutter-apkapp-debug.apk.
Installing buildappoutputsflutter-apkapp-debug.apk...
Debug service listening on ws://127.0.0.1:50498/Z0uovONnF5A=/ws
Syncing files to device AOSP on IA Emulator...
E/flutter ( 8435): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(null-error, Host platform returned null value for non-null return value., null, null)
E/flutter ( 8435): #0      FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:248:7)
E/flutter ( 8435): <asynchronous suspension>
E/flutter ( 8435): #1      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25)
E/flutter ( 8435): <asynchronous suspension>
E/flutter ( 8435): #2      Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31)
E/flutter ( 8435): <asynchronous suspension>
E/flutter ( 8435): #3      main (package:kp_app/main.dart:8:3)
E/flutter ( 8435): <asynchronous suspension>
E/flutter ( 8435): 

This is my main.dart as you can see I have followed instructions, I did this last month no problem this month I try again, problem

import 'package:easy_localization/easy_localization.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  await EasyLocalization.ensureInitialized();
  SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      statusBarIconBrightness: Brightness.dark));


  runApp(EasyLocalization(
    supportedLocales: const [
      Locale('en'),
      Locale('ar'),
      Locale('es'),
      Locale('fr'),
      Locale('de'),
      Locale('it'),
      Locale('pt'),
      Locale('ru'),
      Locale('zh'),
      Locale('ja'),
      Locale('hi'),
      Locale('sw')
    ],
    path: 'assets/translations',
    fallbackLocale: const Locale('en'),

    //Default language
    startLocale: const Locale('en'),
    useOnlyLangCode: true,
    child: const NewApp(),
  ));
}

class NewApp extends StatelessWidget {
  const NewApp({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.blue,
      child: const Center(child: Text('My New APp')),
    );
  }
}

This is my app level build.gradle and as you see it is intact

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

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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'

//apply plugin: 'dev.flutter.flutter-gradle-plugin'

android {
    namespace "com.prowebsolutions.kp_app"
    compileSdkVersion 33
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

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

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.prowebsolutions.kp_app"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion 28
        //noinspection OldTargetApi
        targetSdkVersion 31
//        targetSdkVersion flutter.targetSdkVersion
        multiDexEnabled true
        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
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:32.3.1')
    implementation 'com.google.firebase:firebase-analytics'
}

This is also my project level build.gradle intact

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.4.0'
    }
}

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
}

2

Answers


  1. Hello is the Google services version try downgrade to 4.3.15
    Other solution is migrate to buildscript to plugin block check the next:

    File -> android/settings.gradle

    pluginManagement {
        repositories {
            google()
            mavenCentral()
            gradlePluginPortal()
        }
        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")
    
        plugins {
            id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
        }
    }
    
    include ":app"
    
    apply from: "${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle/app_plugin_loader.gradle"
    

    File -> android/build.gradle

    plugins {
        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.3.15' apply false
        id 'com.google.firebase.crashlytics' version '2.9.9' apply false
    }
    
    allprojects {
        repositories {
            google()
            mavenCentral()
        }
    }
    
    rootProject.buildDir = '../build'
    
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
        project.evaluationDependsOn(':app')
    }
    
    tasks.register("clean", Delete) {
        delete rootProject.buildDir
    }
    

    File -> 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'
    }
    
    android {
        namespace "com.example.test_app"
        compileSdkVersion flutter.compileSdkVersion
        ndkVersion flutter.ndkVersion
    
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    
        kotlinOptions {
            jvmTarget = '1.8'
        }
    
        sourceSets {
            main.java.srcDirs += 'src/main/kotlin'
        }
    
        defaultConfig {
            // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
            applicationId "com.example.test_app"
            // You can update the following values to match your application needs.
            // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
            minSdkVersion localProperties.getProperty('flutter.minSdkVersion')
            targetSdkVersion flutter.targetSdkVersion
            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
            }
        }
    }
    
    flutter {
        source '../..'
    }
    
    dependencies {
        implementation platform('com.google.firebase:firebase-bom:32.3.1')
        implementation 'com.google.firebase:firebase-crashlytics'
        implementation 'com.google.firebase:firebase-analytics'
    }
    

    File -> android/local.properties

    #Add your Android SDK path    
    sdk.dir=D:\Users\Alex\Sdk
    #Add your Flutter path SDK  
    flutter.sdk=D:\Users\Alex\Flutter 
    flutter.minSdkVersion=24
    flutter.buildMode=debug
    flutter.versionName=1.0.0
    flutter.versionCode=1
    

    Finally execute flutter clean after flutter pub get --no-example

    And check google-services.json file

    enter image description here

    Login or Signup to reply.
  2. Google services version downgrade to 4.3.15 from the answer of Alex works for me.

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