flutter 包冲突问题

来源:2-10 布局方式及差异

失眠的小绵羊

2025-08-06

老师好,我现在做的一项目中,升级sdk35后出现了不同的问题,
请帮看一下,老师你可以远程帮看一下,可能我说的不如你直接看到的错误更直接,可以约个时间

如:

[  +99 ms] FAILURE: Build failed with an exception.
[   +4 ms] * What went wrong:
[        ] A problem occurred configuring project ':package_info'.
[        ] > Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
[        ]    > Namespace not specified. Specify a namespace in the module's build file. See
https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.
[        ]      If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to
the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information
about using the AGP Upgrade Assistant.
[   +1 ms] * Try:
[        ] > Run with --debug option to get more log output.
[        ] > Run with --scan to get full insights.
[   +1 ms] > Get more help at https://help.gradle.org.
[        ] * Exception is:

项目各配置信息
1、android/build.gradle 配置信息

buildscript {
    ext.kotlin_version = '1.8.0'
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
         classpath 'com.android.tools.build:gradle:8.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        
    }
}
 
allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
 
tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

android/settings 配置:

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-gradle-plugin" version "1.0.0" apply false
    }
}
 
plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    // id "com.android.application" version "7.3.0" apply false
}

include ":app" 

android/gradle/wrapper/gradle-wrapper.properties 配置

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
# distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
# distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
# distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip

android/app/build.gradle 配置如下

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

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.yjl.monitorx_app"


    //  flutter.compileSdkVersion
    compileSdkVersion   35 //flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    // compileOptions {
    //     sourceCompatibility JavaVersion.VERSION_1_8
    //     targetCompatibility JavaVersion.VERSION_1_8
    // }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    lint {
        baseline = file("lint-baseline.xml")
    }
   lintOptions {
        // 如打包出现Failed to transform libs.jar to match attributes
        checkReleaseBuilds false
    }
    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.yjl.monitorx_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.
       // 
        //   minSdk = 19    //20 
          minSdkVersion 21// 更新此行
        // minSdkVersion flutter.minSdkVersion  // 21 
        // flutter.targetSdkVersion
        targetSdkVersion 35 //flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        //'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'
        ndk {
            abiFilters  'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'
        }
    }
    // dependencies{
    //     implementation project(':monitorx')
    // }
    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
            minifyEnabled false //删除无用代码
            shrinkResources false //删除无用资源 
            ndk {
                abiFilters "armeabi",  "arm64-v8a", "x86"
            }
        }
          debug {
            ndk { //这里要加上,否则debug包会出问题,后面三个为可选,x86建议加上不然部分模拟器回报错
                abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'
            }
        }
        
    }
}

flutter {
    source '../..'
}
写回答

1回答

马超老师

2025-09-16

你好。

看了日志以及你的配置代码,应该是AGP版本导致的问题,可以尝试一下以下步骤排查:
1、使用现代化替代插件(推荐)

# 在 pubspec.yaml 中替换
dependencies:
# package_info: ^2.0.2  # 移除这个
package_info_plus: ^4.2.0  # 使用这个替代

改完之后可能有些代码需要做迁移适配,但是是最优的方法。如果还是不行,那就尝试第二步:

2、降级AGP

// android/build.gradle
dependencies {
    classpath 'com.android.tools.build:gradle:7.4.2'  // 降级到 7.x
}

这样可以让AGP版本匹配。如果还是不行,可以手动修复插件的问题。

先试试这几个方案,假如还没解决,可以给我留言

0
0

基于Flutter 3.x 实战跨平台仿抖音App混合开发

以短视频APP为例,快速上手原生/Flutter 混合开发

496 学习 · 124 问题

查看课程