firebase 未行程的例外状况:PlatformException(null-error,主机平台为非空返回值返回空值

wwwo4jvm  于 2023-10-22  发布在  其他
关注(0)|答案(1)|浏览(147)

我看到了很多关于下面错误的问题:“[错误:flutter/runtime/dart_vm_initializer.cc(41)]未处理的异常:PlatformException(null-error,Host platform returned null value for non-null return value.,null,null)”但是所有的解决方案都没有解决我的问题,我已经按照所有的说明同上,添加依赖关系等等。我的构建。gradles是好的,但当我运行我仍然得到错误。一个月前这对我很有效,但现在我不这样做了; I don’我不知道这个月发生了什么事。

  1. Launching lib\main.dart on AOSP on IA Emulator in debug mode...
  2. Running Gradle task 'assembleDebug'...
  3. Parameter format not correct -
  4. Built build\app\outputs\flutter-apk\app-debug.apk.
  5. Installing build\app\outputs\flutter-apk\app-debug.apk...
  6. Debug service listening on ws://127.0.0.1:50498/Z0uovONnF5A=/ws
  7. Syncing files to device AOSP on IA Emulator...
  8. 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)
  9. E/flutter ( 8435): #0 FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:248:7)
  10. E/flutter ( 8435): <asynchronous suspension>
  11. E/flutter ( 8435): #1 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25)
  12. E/flutter ( 8435): <asynchronous suspension>
  13. E/flutter ( 8435): #2 Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31)
  14. E/flutter ( 8435): <asynchronous suspension>
  15. E/flutter ( 8435): #3 main (package:kp_app/main.dart:8:3)
  16. E/flutter ( 8435): <asynchronous suspension>
  17. E/flutter ( 8435):

这是我的主要。 dart 你可以看到我已经按照指示,我这样做上个月没有问题这个月我再试一次,问题

  1. import 'package:easy_localization/easy_localization.dart';
  2. import 'package:firebase_core/firebase_core.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/services.dart';
  5. void main() async {
  6. WidgetsFlutterBinding.ensureInitialized();
  7. await Firebase.initializeApp();
  8. await EasyLocalization.ensureInitialized();
  9. SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
  10. statusBarColor: Colors.transparent,
  11. statusBarIconBrightness: Brightness.dark));
  12. runApp(EasyLocalization(
  13. supportedLocales: const [
  14. Locale('en'),
  15. Locale('ar'),
  16. Locale('es'),
  17. Locale('fr'),
  18. Locale('de'),
  19. Locale('it'),
  20. Locale('pt'),
  21. Locale('ru'),
  22. Locale('zh'),
  23. Locale('ja'),
  24. Locale('hi'),
  25. Locale('sw')
  26. ],
  27. path: 'assets/translations',
  28. fallbackLocale: const Locale('en'),
  29. //Default language
  30. startLocale: const Locale('en'),
  31. useOnlyLangCode: true,
  32. child: const NewApp(),
  33. ));
  34. }
  35. class NewApp extends StatelessWidget {
  36. const NewApp({super.key});
  37. @override
  38. Widget build(BuildContext context) {
  39. return Container(
  40. color: Colors.blue,
  41. child: const Center(child: Text('My New APp')),
  42. );
  43. }
  44. }

这是我的应用程序级别的build.gradle,正如你所看到的,它是完整的

  1. //plugins {
  2. // id "com.android.application"
  3. // id "kotlin-android"
  4. // id "dev.flutter.flutter-gradle-plugin"
  5. // id 'com.google.gms.google-services'
  6. //}
  7. def localProperties = new Properties()
  8. def localPropertiesFile = rootProject.file('local.properties')
  9. if (localPropertiesFile.exists()) {
  10. localPropertiesFile.withReader('UTF-8') { reader ->
  11. localProperties.load(reader)
  12. }
  13. }
  14. def flutterRoot = localProperties.getProperty('flutter.sdk')
  15. if (flutterRoot == null) {
  16. throw GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
  17. }
  18. def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
  19. if (flutterVersionCode == null) {
  20. flutterVersionCode = '1'
  21. }
  22. def flutterVersionName = localProperties.getProperty('flutter.versionName')
  23. if (flutterVersionName == null) {
  24. flutterVersionName = '1.0'
  25. }
  26. apply plugin: 'com.android.application'
  27. apply plugin: 'kotlin-android'
  28. apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
  29. apply plugin: 'com.google.gms.google-services'
  30. //apply plugin: 'dev.flutter.flutter-gradle-plugin'
  31. android {
  32. namespace "com.prowebsolutions.kp_app"
  33. compileSdkVersion 33
  34. ndkVersion flutter.ndkVersion
  35. compileOptions {
  36. sourceCompatibility JavaVersion.VERSION_1_8
  37. targetCompatibility JavaVersion.VERSION_1_8
  38. }
  39. kotlinOptions {
  40. jvmTarget = '1.8'
  41. }
  42. sourceSets {
  43. main.java.srcDirs += 'src/main/kotlin'
  44. }
  45. defaultConfig {
  46. // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
  47. applicationId "com.prowebsolutions.kp_app"
  48. // You can update the following values to match your application needs.
  49. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
  50. minSdkVersion 28
  51. //noinspection OldTargetApi
  52. targetSdkVersion 31
  53. // targetSdkVersion flutter.targetSdkVersion
  54. multiDexEnabled true
  55. versionCode flutterVersionCode.toInteger()
  56. versionName flutterVersionName
  57. }
  58. buildTypes {
  59. release {
  60. // TODO: Add your own signing config for the release build.
  61. // Signing with the debug keys for now, so `flutter run --release` works.
  62. signingConfig signingConfigs.debug
  63. }
  64. }
  65. }
  66. flutter {
  67. source '../..'
  68. }
  69. dependencies {
  70. implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
  71. implementation platform('com.google.firebase:firebase-bom:32.3.1')
  72. implementation 'com.google.firebase:firebase-analytics'
  73. }

这也是我的项目级构建。

  1. buildscript {
  2. ext.kotlin_version = '1.7.10'
  3. repositories {
  4. google()
  5. mavenCentral()
  6. }
  7. dependencies {
  8. classpath 'com.android.tools.build:gradle:7.3.1'
  9. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  10. classpath 'com.google.gms:google-services:4.4.0'
  11. }
  12. }
  13. allprojects {
  14. repositories {
  15. google()
  16. mavenCentral()
  17. }
  18. }
  19. rootProject.buildDir = '../build'
  20. subprojects {
  21. project.buildDir = "${rootProject.buildDir}/${project.name}"
  22. }
  23. subprojects {
  24. project.evaluationDependsOn(':app')
  25. }
  26. tasks.register("clean", Delete) {
  27. delete rootProject.buildDir
  28. }
e4yzc0pl

e4yzc0pl1#

你好是谷歌服务版本尝试降级到4.3.15其他解决方案是迁移到buildscript到插件块检查下:
文件-> android/settings.gradle

  1. pluginManagement {
  2. repositories {
  3. google()
  4. mavenCentral()
  5. gradlePluginPortal()
  6. }
  7. def flutterSdkPath = {
  8. def properties = new Properties()
  9. file("local.properties").withInputStream { properties.load(it) }
  10. def flutterSdkPath = properties.getProperty("flutter.sdk")
  11. assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
  12. return flutterSdkPath
  13. }
  14. settings.ext.flutterSdkPath = flutterSdkPath()
  15. includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
  16. plugins {
  17. id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
  18. }
  19. }
  20. include ":app"
  21. apply from: "${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle/app_plugin_loader.gradle"

文件-> android/build.gradle

  1. plugins {
  2. id 'com.android.application' version '7.3.0' apply false
  3. id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
  4. id 'com.google.gms.google-services' version '4.3.15' apply false
  5. id 'com.google.firebase.crashlytics' version '2.9.9' apply false
  6. }
  7. allprojects {
  8. repositories {
  9. google()
  10. mavenCentral()
  11. }
  12. }
  13. rootProject.buildDir = '../build'
  14. subprojects {
  15. project.buildDir = "${rootProject.buildDir}/${project.name}"
  16. project.evaluationDependsOn(':app')
  17. }
  18. tasks.register("clean", Delete) {
  19. delete rootProject.buildDir
  20. }

文件-> android/app/build.gradle

  1. plugins {
  2. id "com.android.application"
  3. id "kotlin-android"
  4. id "dev.flutter.flutter-gradle-plugin"
  5. id 'com.google.gms.google-services'
  6. id 'com.google.firebase.crashlytics'
  7. }
  8. def localProperties = new Properties()
  9. def localPropertiesFile = rootProject.file('local.properties')
  10. if (localPropertiesFile.exists()) {
  11. localPropertiesFile.withReader('UTF-8') { reader ->
  12. localProperties.load(reader)
  13. }
  14. }
  15. def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
  16. if (flutterVersionCode == null) {
  17. flutterVersionCode = '1'
  18. }
  19. def flutterVersionName = localProperties.getProperty('flutter.versionName')
  20. if (flutterVersionName == null) {
  21. flutterVersionName = '1.0'
  22. }
  23. android {
  24. namespace "com.example.test_app"
  25. compileSdkVersion flutter.compileSdkVersion
  26. ndkVersion flutter.ndkVersion
  27. compileOptions {
  28. sourceCompatibility JavaVersion.VERSION_1_8
  29. targetCompatibility JavaVersion.VERSION_1_8
  30. }
  31. kotlinOptions {
  32. jvmTarget = '1.8'
  33. }
  34. sourceSets {
  35. main.java.srcDirs += 'src/main/kotlin'
  36. }
  37. defaultConfig {
  38. // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
  39. applicationId "com.example.test_app"
  40. // You can update the following values to match your application needs.
  41. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
  42. minSdkVersion localProperties.getProperty('flutter.minSdkVersion')
  43. targetSdkVersion flutter.targetSdkVersion
  44. versionCode flutterVersionCode.toInteger()
  45. versionName flutterVersionName
  46. }
  47. buildTypes {
  48. release {
  49. // TODO: Add your own signing config for the release build.
  50. // Signing with the debug keys for now, so `flutter run --release` works.
  51. signingConfig signingConfigs.debug
  52. }
  53. }
  54. }
  55. flutter {
  56. source '../..'
  57. }
  58. dependencies {
  59. implementation platform('com.google.firebase:firebase-bom:32.3.1')
  60. implementation 'com.google.firebase:firebase-crashlytics'
  61. implementation 'com.google.firebase:firebase-analytics'
  62. }

文件-> android/local.properties

  1. #Add your Android SDK path
  2. sdk.dir=D:\\Users\\Alex\\Sdk
  3. #Add your Flutter path SDK
  4. flutter.sdk=D:\\Users\\Alex\\Flutter
  5. flutter.minSdkVersion=24
  6. flutter.buildMode=debug
  7. flutter.versionName=1.0.0
  8. flutter.versionCode=1

最后在flutter pub get --no-example之后执行flutter clean
并检查google-services.json文件

展开查看全部

相关问题