You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter构建APK失败:找不到匹配的firebase-sessions版本

构建Flutter APK时Firebase依赖冲突问题

环境信息

Flutter版本

Flutter is already up to date on channel stable
Flutter 3.10.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision f468f3366c (8 days ago) • 2023-07-12 15:19:05 -0700
Engine • revision cdbeda788a
Tools • Dart 3.0.6 • DevTools 2.23.1

Gradle版本

Android gradle plugin version: 7.4.2
Gradle version: 7.6.2

Flutter Firebase依赖包版本

firebase_analytics: ^10.4.4
firebase_crashlytics: ^3.3.4
firebase_core: ^2.15.0
cloud_firestore: ^4.8.3
firebase_storage: ^11.2.5
firebase_auth: ^4.7.1
cloud_functions: ^4.3.4

报错信息

构建APK时失败,报错如下:

* What went wrong:
Execution failed for task ':app:checkReleaseAarMetadata'.
> Could not resolve all files for configuration ':app:releaseRuntimeClasspath'.
   > Could not find any version that matches com.google.firebase:firebase-sessions:[15.0.0, 16.0.0).
     Versions that do not match: 1.0.0
     Required by:
         project :app > project :firebase_crashlytics > com.google.firebase:firebase-crashlytics:18.4.0

Gradle配置

项目层级Gradle配置

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

    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.15'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.7'
    }
}

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
}

App层级Gradle配置

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/' }
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.14.0'
    }
}

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"
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

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

android {
    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 {
        applicationId "com.myappid.app"
        minSdkVersion 24
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.firebase:firebase-analytics-ktx:21.3.0'
}

解决方案

方案1:强制指定firebase-sessions版本

在App层级的android块中添加configurations节点,强制解析可用版本的firebase-sessions:

android {
    // 保留原有配置...

    configurations.all {
        resolutionStrategy {
            force 'com.google.firebase:firebase-sessions:1.0.0'
        }
    }
}

方案2:升级Firebase Crashlytics插件版本

将项目层级Gradle中的firebase-crashlytics-gradle插件版本升级到兼容的新版本,比如2.9.8:

classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.8'

方案3:更新Flutter Firebase依赖包

将所有Firebase相关包升级到最新稳定版,执行命令:

flutter pub upgrade firebase_crashlytics firebase_core firebase_analytics cloud_firestore firebase_storage firebase_auth cloud_functions

方案4:清理缓存后重新构建

执行以下命令清理项目缓存,再尝试构建:

flutter clean
flutter pub get
cd android && ./gradlew clean build

内容的提问来源于stack exchange,提问作者Mahmoud Al-Mohammed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 16:33:17