I’m having problem starting Firebase after migrating to SDK 33 and Gradle 8.
Error:
PlatformException (PlatformException(channel-error, Unable to establish connection on channel., null, null))
Part of the code:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
pubspec.yaml:
environment:
sdk: '>=2.12.0 <3.0.0'
module:
androidX: true
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
cupertino_icons: ^1.0.3
google_fonts: ^4.0.4 #1.1.1
http: ^0.13.3
flutter_math_fork: ^0.7.1
intl_utils: ^2.2.0
carousel_slider: ^4.2.1 #^2.3.1
provider: ^6.0.5 #4.3.2+3
textstyle_extensions: ^2.0.0-nullsafety
cached_network_image: ^3.1.0-alpha.1
# login added function
flutter_facebook_auth: ^5.0.11 #4.0.1 #3.5.7 #3.3.3+1 #2.0.0 ^4.4.0+1
image_picker: ^1.0.4 #0.6.7+21
flutter_easyloading: ^3.0.0 # 2.1.3
auto_size_text: ^3.0.0-nullsafety.0
image: ^4.1.3
flutter_html: 3.0.0-beta.2
html_unescape: ^2.0.0
pull_to_refresh: ^2.0.0
clipboard: ^0.1.3
flutter_rating_bar: ^4.0.0
page_transition: ^2.0.2
badges: ^3.1.2
overlay_support: ^2.1.0
flutter_inappwebview: ^5.3.2
photo_view: ^0.14.0 #0.11.1
image_cropper: ^4.0.1
vibration: ^1.7.4-nullsafety.0
vibration_web: ^1.6.5-nullsafety.0
youtube_plyr_iframe: ^2.0.4
permission_handler: ^11.0.1
what3words: ^3.1.0-nullsafety.3
geolocator: ^10.1.0
video_player_web: ^2.1.2
wakelock_web: ^0.4.0
flutter_rounded_date_picker: ^3.0.4
share_plus: ^7.2.1
shared_preferences: ^2.2.2
local_auth: ^2.1.7
url_launcher: ^6.2.1
firebase_core: ^2.24.0
firebase_messaging: ^14.7.6
firebase_auth: ^4.15.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- assets/img/
- assets/icon/
- assets/payment/
- lib/lang/en.json
- lib/lang/mn.json
fonts:
- family: Mogul
fonts:
- asset: assets/fonts/mogul.ttf
flutter_intl:
enabled: true
Project build.gradle:
buildscript {
ext.kotlin_version = '1.8.22'
repositories {
google()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:8.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.15'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
App 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 new FileNotFoundException("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"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
namespace 'com.my.package'
compileSdk 33
sourceSets {
main.java.srcDirs = ['src/main/kotlin', 'build/generated/source/buildConfig/release', 'build/generated/source/buildConfig/debug']
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId 'com.my.package'
minSdkVersion 21
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
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
signingConfig signingConfigs.debug
minifyEnabled true
shrinkResources true
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
}
}
lint {
disable 'InvalidPackage'
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'androidx.multidex:multidex:2.0.1'
implementation platform('com.google.firebase:firebase-bom:32.6.0')
implementation 'com.google.firebase:firebase-messaging:23.3.1'
}
apply plugin: 'com.google.gms.google-services'
Flutter Doctor -v:
[√] Flutter (Channel stable, 3.16.1, on Microsoft Windows [Version 10.0.22621.2715], locale en-US)
• Flutter version 3.16.1 on channel stable at C:Developmentflutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 7f20e5d18c (3 days ago), 2023-11-27 09:47:30 -0800
• Engine revision 22b600f240
• Dart version 3.2.1
• DevTools version 2.28.3
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at C:UsersMSMAppDataLocalAndroidsdk
• Platform android-34, build-tools 34.0.0
• Java binary at: C:Program FilesAndroidAndroid Studiojbrbinjava
• Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:Program Files (x86)GoogleChromeApplicationchrome.exe
[√] Visual Studio - develop Windows apps (Visual Studio Enterprise 2019 16.11.27)
• Visual Studio at C:Program Files (x86)Microsoft Visual Studio2019Enterprise
• Visual Studio Enterprise 2019 version 16.11.33801.447
• Windows 10 SDK version 10.0.19041.0
[√] Android Studio (version 2022.3)
• Android Studio at C:Program FilesAndroidAndroid Studio
• 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-b2043.56-10027231)
[√] VS Code (version 1.79.2)
• VS Code at C:UsersMSMAppDataLocalProgramsMicrosoft VS Code
• Flutter extension version 3.76.0
[√] Connected device (4 available)
• sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22621.2715]
• Chrome (web) • chrome • web-javascript • Google Chrome 119.0.6045.124
• Edge (web) • edge • web-javascript • Microsoft Edge 119.0.2151.93
[√] Network resources
• All expected network resources are available.
I already tried:
- flutter clean, flutter pub upgrade, flutter pub outdated
- adding firebasebom to gradle and removing it
- already installed Flutterfire CLI and flutterfire configure
- Debugging on android device, same results
2
Answers
Probably you have updated Flutter but forgot to synchronize the packages.
run this in your terminal:
flutter pub outdated
and then
flutter pub upgrade outdated_package
Then clean and build once more.
Try to run your app in release mode it can help to find the root cause of crashing
Running commands:
App by default runs on debug mode, it is a bit janky but needed to provide features like hot reload and hot restart. However, if you want to run the app in other modes, try these commands: