6

I have Android Studio build problem.

Build fails only when changing the minSdk=29 with follwing error.
( It's OK with minSdk=28 )

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.example.aaa"
        minSdkVersion 29  // build fails with 29, it's OK with 28
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

Fail messages on Android Studio build console

    - Build: build failed

       - Run build :

         ...

         Caused by: com.android.tools.r8.utils.AbortException


       - Andriod issues: (1 error)

         Dex file with version '38' cannot be used with min sdk level '29'. 

If anyone resolved this problem, please share your know-hows.

Thank you.

Ola Ström
  • 4,136
  • 5
  • 22
  • 41
teranian
  • 69
  • 1
  • 4
  • 2
    https://developer.android.com/guide/topics/manifest/uses-sdk-element Please read on this . `android:minSdkVersion`: ""An integer designating the minimum API Level required for the application to run"" The latest version of Android is Android Pie which uses SDK version 28. – Sunil Sunny Aug 22 '19 at 02:30
  • try to add compile "com.android.tools:r8:1.4.93" to the build dependencies (not your app dependencies). Something like: `classpath 'com.android.tools:r8:1.4.93' classpath 'com.android.tools.build:gradle:3.4.2'` – Gabriele Mariotti Aug 22 '19 at 05:51
  • This problem was resolved after updating Android Studio version 3.5 ! Thank you. Gabriele Mariotti, sunil sunny. – teranian Aug 23 '19 at 04:56
  • 3
    Clean & Rebuild, and/or Invalidate caches & restart solved my issue. – Salman Khalid Mar 24 '20 at 15:25
  • I am getting this error with Android Studio and gradle 3.6.2. Any solution other than downgrading? – Jordan Apr 07 '20 at 20:31

2 Answers2

13

I came across this recently when updating a project for Android studio 3.5.3 to 3.6.3, however I manually changed gradle-wrapper.properties and the project's build.gradle before even opening the project.

In my case I was able to clean the build, delete the .gradle and .idea folders and rebuild without issue.

Edit: As stated in the comments, it is worthwhile to try a clean-rebuild first, rather than the "Scorched Earth" approach of deleting .gradle and .idea folders. Deleting them will take longer to recover from and blow away all your nice IDE settings!

Michael Marsella
  • 470
  • 5
  • 10
0

This is because of latest gradle version : classpath 'com.android.tools.build:gradle:3.5.3'

in Android 6.0 and lower android versions. In order to fix it you can downgrade the gradle version as follows :

classpath 'com.android.tools.build:gradle:3.5.1'

It will run on all android versions perfectly.