Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Gradle cannot find the compile() method in build.gradle

ErrorCould not find method compile() for arguments [...] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Short answer

Gradle 7 removed the compile and runtime configurations, so a dependencies block that still says compile fails. Replace compile with implementation (or api for a library that exposes the dependency), and testCompile with testImplementation. Then sync the project again.

  • Applies to Gradle 8.x, Gradle 9, Android Gradle plugin 8.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find every old configuration name in your build files.

    grep -rnE "^\s*(compile|testCompile|runtime|androidTestCompile|debugCompile)\b" --include=build.gradle .
  2. 2Match what you see, then jump to its fix

    1. 1Could not find method compile() for argumentsThe dependencies block uses the removed compile configurationFix
    2. 2Could not find method debugCompile() or androidTestCompile()A pasted snippet from an old tutorial uses debugCompile or androidTestCompileFix

What does the error look like?

  • Could not find method compile() for arguments [...] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
  • Could not find method testCompile() for arguments

Cause 1 of 2

The dependencies block uses the removed compile configuration

1Check

The Gradle upgrade guide says that in Gradle 7 both the compile and runtime configurations were removed. Any line that starts with compile in a dependencies block is the cause.

./gradlew --version

2Fix

Use implementation for a dependency the module only needs itself. Use api only when other modules must see it at compile time. Android's own docs say to prefer implementation.

dependencies {
    implementation 'androidx.appcompat:appcompat:1.7.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
}

3Verify

Sync the project, then build.

./gradlew assembleDebug

Confirmed by docs.gradle.org

Did this fix it?

Cause 2 of 2

A pasted snippet from an old tutorial uses debugCompile or androidTestCompile

1Check

Variant-specific names follow the same rule: the Compile suffix is gone. The Android dependencies page lists the configurations that exist today.

grep -rnE "(debug|release|androidTest)Compile" --include=build.gradle .

2Fix

Rename each one to its Implementation form, such as debugImplementation or androidTestImplementation.

dependencies {
    debugImplementation 'androidx.compose.ui:ui-tooling:1.7.0'
}

3Verify

Run the build and confirm it passes the configuration phase.

./gradlew help

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Copy dependency lines only from the current library documentation, not from old tutorials.
  • Keep versions in a gradle/libs.versions.toml version catalog so build files hold no raw coordinates.
  • Upgrade Gradle in the same pull request that updates build files, so the break is found at once.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Android Studio cannot pair the phone over Wi-Fi

The Pair devices over Wi-Fi dialog lists no device

Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.