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

使用IntelliJ Idea开发Flutter时build.gradle报错,Properties()与GradleException()异常求助

Hey there, let's fix those Properties() and GradleException() errors in your Flutter project's android/app/build.gradle file—this is a super common issue after Gradle updates, so you're not alone!

Fixing Properties() and GradleException() Errors in Flutter's Android Build.gradle

Why This Happens

Starting with Gradle 7.0+, the old Properties class (from java.util) and GradleException have been deprecated or shadowed by newer Gradle API equivalents. Most Flutter projects hit this when upgrading Flutter, Gradle, or the Android Gradle Plugin (AGP).

Step 1: Resolve the Properties() Error

You probably have code like this in your app-level build.gradle:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

The fix is to explicitly reference the full path to the Java Properties class to avoid conflicts with Gradle's own Properties type:

def localProperties = new java.util.Properties()

This is the quickest, safest fix for Flutter projects—no need to overhaul your setup.

Step 2: Fix the GradleException() Error

Anywhere you're throwing a GradleException, you have two options:

Option 1: Use the full class path

Replace instances of GradleException with org.gradle.api.GradleException:

// Old code
throw new GradleException("Failed to load local properties")

// Fixed code
throw new org.gradle.api.GradleException("Failed to load local properties")

Option 2: Add an import

Add this line at the very top of your build.gradle file, then use GradleException normally:

import org.gradle.api.GradleException

// Now you can use this as before
throw new GradleException("Failed to load local properties")

Step 3: Verify Gradle & AGP Version Compatibility (If Needed)

Sometimes these errors pop up if your AGP and Gradle versions are mismatched. Check your top-level android/build.gradle and gradle/wrapper/gradle-wrapper.properties to ensure they're compatible:

  • AGP 7.0+ requires Gradle 7.0+
  • AGP 8.0+ requires Gradle 8.0+

For example, update your top-level build.gradle dependencies:

buildscript {
    ext.kotlin_version = '1.9.0' // Use a version compatible with your AGP
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.1.0' // Match your Gradle version
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

And your gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip

Step 4: Clean & Rebuild

After making these changes:

  • Run flutter clean in your terminal
  • Run flutter pub get
  • Rebuild your project in IntelliJ or Android Studio

That should wipe out those exceptions! If you still run into issues, double-check that you didn't miss any instances of Properties() or GradleException() in both the top-level and app-level build.gradle files.

内容的提问来源于stack exchange,提问作者Devansh Baldwa

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:16:47