299

I've got a gradle FAILURE:

..."Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0."

Case description:

  • Attached to the project codebase the next libs:

APP/build.gradle

    //(Required) Writing and executing Unit Tests on the JUnit Platform 
testImplementation "org.junit.jupiter:junit-jupiter-api:5.2.0"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.2.0"
    // (Optional) If you need "Parameterized Tests"
testImplementation "org.junit.jupiter:junit-jupiter-params:5.2.0"
    // (Optional) If you also have JUnit 4-based tests
testImplementation "junit:junit:4.12"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.2.0"

testImplementation "io.mockk:mockk:1.8.5"
  • Updated the gradle-wrapper.properties

    distributionUrl=https....gradle-4.4-all.zip to 4.7-all

  • after all of that gradle was built success

  • created the test calss

    @TestInstance(TestInstance.Lifecycle.PER_CLASS)
      class TestClass {
    
      @Test
      internal fun testName() {
        Assert.assertEquals(2, 1 + 1)
      }
    }
    
  • ran the test and got the FAILURE message. enter image description here

  • ran the Gradle build with a command line argument ./gradlew --warning-mode=all to see what exactly the deprecated features are. enter image description here

As a result I couldn't build the app and I've got that FAILURE: message.

Mark Storer
  • 15,672
  • 3
  • 42
  • 80
Philipp Buhaievskiy
  • 3,217
  • 2
  • 10
  • 17

32 Answers32

167

Run the Gradle build with a command line argument --warning-mode=all to see what exactly the deprecated features are.

It will give you a detailed description of found issues with links to the Gradle docs for instructions how to fix your build.

Adding --stacktrace to that, you will also be able to pinpoint where the warning comes from, if it's triggered by outdated code in one of the plugins and not your build script.

hotkey
  • 140,743
  • 39
  • 371
  • 326
  • I updated the description of the issue, using this suggestion. – Philipp Buhaievskiy Aug 01 '18 at 14:23
  • 40
    When running `react-native run-android --warning-mode all` I get `error: unknown option --warning-mode'` – Ren May 13 '19 at 17:03
  • 47
    Try running `gradle build --warning-mode=all` – Jordan Daniels May 26 '19 at 23:12
  • 1
    @Led, the deprecation warnings could arise due to numerous reasons, from deprecated feature used in the build script to third-party Gradle plugins being outdated or mistakenly calling the deprecated API. This answer offers a way to find what exactly is causing deprecation warnings, so, having learned that, you can search for solutions to a more specific problem. – hotkey Mar 10 '21 at 10:09
  • 4
    @JordanDaniels Where am I supposed to add that command, in Android Studio Terminal? When I write there, I get: 'gradle' is not recognized as an internal or external command, operable program or batch file. – Stefan Aug 08 '21 at 07:50
  • 24
    Use `npx react-native run-android -- --warning-mode=all` for React-Native – Lakshit Nagar Aug 22 '21 at 05:34
  • 1
    @Hassa I got the same error and I replaced `gradle` with `gradlew` and it worked for me. – Bhanu Prakash Aug 26 '21 at 01:32
  • 2
    @Hassa if you're using Windows, you can go to search in the taskbar and type 'cmd' for the command prompt. Then navigate to your project directory. e.g. C:\Users\Your Computer Name\My Projects Folder\My Project Name. Type gradlew build --warning-mode=all and hit enter – gig6 Oct 02 '22 at 18:21
  • cd android && gradlew build --warning-mode=all – selcukctn Feb 21 '23 at 09:31
93

Try this one

cd android && ./gradlew clean && ./gradlew :app:bundleRelease
Masum Billah
  • 2,209
  • 21
  • 20
  • 3
    Thanks, Can you plesae explain why this ./gradlew :app:bundleRelease works and this ./gradlew bundleRelease doesn't. – Atikur Rahman Sabuj May 19 '20 at 09:24
  • perfecct worked for me on my cordova-9.0 project :D – minigeek Sep 02 '20 at 06:35
  • 4
    @AtikurRahmanSabuj It depends on how ./gradlew file was written. As the default module in android is "app" and android app can have multiple modules. Also ./gradlew only should work after cleaning. To see all the tasks in the gradlew, execute "./gradlew tasks" which will tell you the available tasks in the gradlew. – Amr Ashraf Nov 23 '20 at 12:41
  • For Apache Cordova and Android 9, error may be resolved by enabling AndroidX. To enable, see: https://cordova.apache.org/announcements/2020/06/29/cordova-android-9.0.0.html – F C Dec 31 '20 at 05:20
  • It give me app-release.aab file and can't open in my mobile phone – Jagroop Mar 27 '22 at 14:50
  • works perfectly for me. Once you run this commend go back to mobile folder and run your android script as usual. The build should be successful. – Dr. Younes Henni Jun 24 '22 at 14:45
  • in my case: npx react-native run-android -- --gradle-version 7.5.1 – Enrique San Martín Nov 16 '22 at 04:47
42

My project was incompatible with Gradle 8.0 .Here's what worked for me: First I wrote this line of code in the Android Studio terminal:

./gradlew build --warning-mode all

When you do that, you will be shown in the logcat what is found to be deprecated or an issue in your project, for me it was the jcenter() repository that needed to be removed in my settings.gradle file and also I needed to update classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21" to classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30" in my build.gradle project file.

Once I did these things, my project built perfectly and installed on my emulator

Kevin Germain
  • 471
  • 3
  • 6
  • 1
    I edited `settings.gradle` and removed jcenter and the warning went away. – user2959589 Jan 06 '22 at 07:42
  • 1
    I am newbie and I didn't know at all how to run the suggestion of using warning-mode all. When I read your answer at first I was stuck but I re-read and saw at the beginning you said in the Android Studio terminal. I tried and I got the same deprecation of jcenter(). I removed and the warning disappeared. IMPORTANT: After doing so, you have to re-sync the app project with Gradle file otherwise the app doesn't install on the emulator or physical device. – wocmultimedia Feb 17 '22 at 18:30
40

The process below worked in my case- First check Gradle Version:

cd android
./gradlew -v

In my case it was 6.5

Go to https://developer.android.com/studio/releases/gradle-plugin and you'll get the plugin version for your gradle version. For gradle version 6.5, the plugin version is 4.1.0

Then go to app/build.gradle and change classpath 'com.android.tools.build:gradle:<plugin_version>

Shafin Hasnat
  • 559
  • 7
  • 9
  • 7
    You just save me from 3 days headache figuring how to fix this. Thanks a million. – cdaiga Oct 11 '21 at 08:17
  • for my case Gradle 7.2 which plugin 7.0 but it is not working. – Chanrithisak Phok Jan 26 '22 at 03:58
  • 1
    Mine is Gradle 7.2 according to the link plugin is 7.1. I changed it and I'm getting this error > Could not find com.android.tools.build:gradle:7.1. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.1/gradle-7.1.pom - https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/7.1/gradle-7.1.pom Required by: project : – William Dec 14 '22 at 21:01
  • not "app/build.gradle", it's "android/build.gradle" – WestMountain May 24 '23 at 04:40
25

I was getting this error. Turns out it only happened when I completely cleaned the RN caches (quite elaborate process) and then created a release build.

If I cleaned the caches, created a debug build and then a release build, everything worked. Bit worrying but works.

Note: My clean command is...

rm -r android/build ; rm -r android/app/src/release/res ; rm -r android/app/build/intermediates ; watchman watch-del-all ; rm -rf $TMPDIR/react-* ; npm start -- --reset-cache

chichilatte
  • 1,697
  • 19
  • 21
13

Important - Answer work only for REACT-NATIVE VS CODE Terminal

In VisualStudio code, you have to run like below then that warning will be omitted.

react-native run-android warning-mode=all

If you run below then you will get the error in terminal When running react-native run-android --warning-mode all I get error: unknown option --warning-mode'

Jayakumar Thangavel
  • 1,884
  • 1
  • 22
  • 29
10

in my case i updated the build.gradle file and make the classpath to latest version from 3.5.2 to 3.6.3

dependencies {
        classpath("com.android.tools.build:gradle:3.6.3") 
    }
Moumit
  • 8,314
  • 9
  • 55
  • 59
9

In my case adding multiDexEnabled true in Android/app/build.gradle file compiled the files.

I will look into removing this in the future, as in the documentation it says 'Before configuring your app to enable use of 64K or more method references, you should take steps to reduce the total number of references called by your app code, including methods defined by your app code or included libraries.'

defaultConfig {
  applicationId "com.peoplesenergyapp"
  minSdkVersion rootProject.ext.minSdkVersion
  targetSdkVersion rootProject.ext.targetSdkVersion
  versionCode 1
  versionName "1.0"
  multiDexEnabled true // <-add this 
}
questerstudios
  • 111
  • 1
  • 6
verunar
  • 884
  • 12
  • 25
  • 1
    "If your app only targets Android 21 or higher (minSdkVersion) then multidex is already enabled by default and you do not need the multidex support library. However, if your minSdkVersion is set to 20 or lower, then you must use the multidex support library". [Source from Flutter](https://firebase.flutter.dev/docs/installation/android#enabling-multidex) – Son Nguyen Aug 31 '21 at 13:29
6

The following solution helped me as I was also getting the same warning. In your project level gradle file, try to change the gradle version in classpath

classpath "com.android.tools.build:gradle:3.6.0" to
classpath "com.android.tools.build:gradle:4.0.1"
kk.
  • 3,747
  • 12
  • 36
  • 67
priyanka.b
  • 91
  • 1
  • 2
5

Update your third party dependencies. for example I updated dependency from implementation 'com.github.ybq:Android-SpinKit:1.1.0' to implementation 'com.github.ybq:Android-SpinKit:1.2.0'. and in my case issue has been solved.

Hiren
  • 1,581
  • 1
  • 12
  • 14
5

It work for me in this issue in a project of react-native:

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.

244 actionable tasks: 2 executed, 242 up-to-date D8: Cannot fit requested classes in a single dex file (# fields: 67296 > 65536) com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: The number of method references in a .dex file cannot exceed 64K. Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html ....

I Did this:

NerioLorona
  • 51
  • 1
  • 2
5

Go to gradle/wrapper/gradle-wrapper.properties change the distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip to the release that is needed (or higher).

Then run again cd android && ./gradlew bundleRelease

Fotios Tsakiris
  • 1,310
  • 1
  • 18
  • 24
4

Uninstall the old app from the device/emulator. It worked for me

cetric
  • 191
  • 1
  • 4
3

Set distributionUrl path in gradle-wrapper-properties files as :

distributionUrl=https://services.gradle.org/distributions/gradle-4.10.2-all.zip

Gautam Dev
  • 399
  • 2
  • 4
  • my gradle had this line.. .distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip Changed it to and it worked. distributionUrl=https://services.gradle.org/distributions/gradle-4.10.2-all.zip – Aaron Medvick Feb 24 '20 at 00:46
3

Solution for the issue: deprecated gradle features were used in this build making it incompatible with gradle 6.0. android studio This provided solution worked for me.

First change the classpath in dependencies of build.gradle of your project From: classpath 'com.android.tools.build:gradle:3.3.1' To: classpath 'com.android.tools.build:gradle:3.6.1'

Then make changes in the gradle-wrapper.properties file this file exists in the Project's gradle>wrapper folder From: distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip To: distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

Then Sync your gradle.

3

i'am using react-native and this works for me :

  1. in root of project cd android and gradlew clean
  2. open task manager in windows
  3. on tab 'Details' hit endtask on both java.exe proccess

long story short > Task :app:installDebug FAILED Fixed by kiling java.exe prossess

faryar76
  • 130
  • 1
  • 8
3

I found my disk space is less than 4 GB and can not get the Gradle lib repo then show

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

just remove tmp and junk files, free up space then try build and resolve problem

dinobi
  • 530
  • 4
  • 7
3

Solved this issue by deleting the .gradle folder from /android and again run npm run android, and it solved this error. Here's a link to the issue: https://github.com/facebook/react-native/issues/28954

sabrim
  • 91
  • 8
3

1)cd android 2) ./gradlew clean 3)./gradlew :app:bundleRelease

then last install npm install command

3

I am using react-native if all above didn't work delete Build and .gridle folder inside the Android folder and run again, That solved my problem

2

Finally decided to downgrade the junit 5 to junit 4 and rebuild the testing environment.

Philipp Buhaievskiy
  • 3,217
  • 2
  • 10
  • 17
2

On a SpringBoot project using IntelliJ and Gradle, I got the warning "Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0" when running my integration test. What solved the problem was: - Going to: File > Settings > Build, Execution, Deployment - Selecting for "Build and run using": Intellij IDEA (instead of "Gradle") - Same for "Run tests using" That did not explain why Gradle is displaying the warning, but that let me perform the test and progress in my work.

Omar D
  • 33
  • 5
2

In my case deleting the whole android folder from the base directory and allowing it to rebuild all of it on eas build fixed this error for me :)

Shep Sims
  • 698
  • 9
  • 27
1

it is due to incompatibility.

please upgrade classpath("com.android.tools.build:gradle:4.0.1") in build.gradle file under android folder.

Manan Gadhiya
  • 480
  • 4
  • 6
1

Check settings.gradle script and remove jcenter() from that it may be causing the issue as it is deprecated.

You're new settings.gradle file should be

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
    plugins {
        id 'com.android.application' version '7.1.0-alpha12'
        id 'com.android.library' version '7.1.0-alpha12'
        id 'org.jetbrains.kotlin.android' version '1.5.21'
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}
rootProject.name = "ComposePlayground"
include ':app'

Take note that ComposePlayground is app name.

Vidyesh Churi
  • 1,899
  • 1
  • 24
  • 33
1

I Sloved this problem by updating my gradle-wrapper.properties file. You have to change this line distributionUrl=https://services.gradle.org/distributions/gradle-7.3.3-bin.zip to the lates gradle build which can be found at The Gradle Wrapper.

Hope that helps someone out there :)

lungu
  • 47
  • 2
  • 10
1

After hours of searching on the web I used this command:
react-native run-android warning-mode=all
on vs code. And it turns out that the error have nothing to do with deprecated modules or any gradle error, it was just that my device was full of storage. I hope it will help someone one day.

Fotios Tsakiris
  • 1,310
  • 1
  • 18
  • 24
1

After none of the above answers worked for me, I managed to solve this issue by upgrading the Gradle plugin to the latest version and using the JDK 11. Hope this helps someone!

mr_dami
  • 81
  • 5
0

Try this solution worked for me.
If you have another app with the same name (or package name) on the device: Rename the app or delete it from your device.

0

For me, the problem was that I ran out of space in my device's internal storage. After deleting a few unnecessary apps, it worked fine.

MoxJet
  • 11
  • 1
-2

It was fixed this kind of error after migrate to AndroidX

  • Go to Refactor ---> Migrate to AndroidX
damith alahakoon
  • 270
  • 4
  • 14
-2

Add implementation("org.slf4j:slf4j-nop:1.7.25") to build.gradle.kts.

4b0
  • 21,981
  • 30
  • 95
  • 142
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 23 '21 at 18:20
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/29903706) – Praveen Sep 24 '21 at 08:50