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

Flutter项目集成New Relic时Android构建报错求助

Flutter集成New Relic Android构建报错:MissingPropertyException: Could not get unknown property 'sources'

报错信息

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Projects\Flutter Projects\easy_invest_app\android\build.gradle' line: 29

* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
   > groovy.lang.MissingPropertyException: Could not get unknown property 'sources' for object of type com.android.build.api.component.analytics.AnalyticsEnabledApplicationVariant.

相关配置文件(android/build.gradle)

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

    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.13'
        classpath "com.newrelic.agent.android:agent-gradle-plugin:7.1.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
}

环境信息

  • Min SDK版本:24
  • 已完成New Relic官方指南配置,但构建失败

解决方案

1. 升级New Relic Gradle插件版本

当前使用的agent-gradle-plugin:7.1.0与Android Gradle插件(AGP)7.1.2存在兼容性问题。建议升级到适配AGP 7.x的最新稳定版本,修改根目录android/build.gradle中的依赖:

classpath "com.newrelic.agent.android:agent-gradle-plugin:7.2.0" // 或更高兼容版本

2. 修复app/build.gradle中过时的variant配置

如果app/build.gradle里有针对变体(variant)的自定义配置,AGP 7.x已废弃variant.sources的访问方式,需调整为新API:
过时代码示例:

newrelic {
    variants {
        each { variant ->
            variant.sources.java.all { source ->
                // 自定义逻辑
            }
        }
    }
}

替换为兼容写法:

newrelic {
    variants {
        each { variant ->
            variant.sourceSets.each { sourceSet ->
                // 自定义逻辑
            }
        }
    }
}

若无特殊自定义需求,仅保留基础插件引用即可:

apply plugin: 'newrelic'

3. 清理缓存并重新构建

执行以下命令清除构建缓存后重新编译:

flutter clean
cd android
./gradlew clean build
cd ..
flutter run

内容的提问来源于stack exchange,提问作者A.HoseinMardy

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 07:27:33