How To Resolve Errors When Change SDK Level In Android Studio

When you add a new dependency library in the android project, you may find it need a higher android SDK level such as version 27 or higher to compile and run. So you should change the project SDK version to fit the needs in such case.

1. New Android SDK File Do Not Exist In Local Folder.

  1. We have introduced how to change the android project SDK version in the article How To Change Minimum SDK Version In Android Studio. But when the new version is higher, you may encounter the below errors in android studio.
    Failed to find target with hash string'android-27' in : C:\Users\Jerry\AppData\Local\Android\Sdk
    
    Install missing platform(s) and sync project
  2. This means you do not have the required version of android SDK installed in your local SDK directory, just click the blue link Install missing platform(s) and sync project under the error message and wait for the android studio to download and install the new SDK files.
  3. When you see the SDK Quickfix Installation install complete success window, that means the download and install successfully. Click the Finish button to complete the install.

2. Failed To Resolve Dependent Support Library Error.

  1. After installing the new SDK, you may find the existing dependency library will not be compatible with the new SDK like the below error messages.
    Error:(29, 13) Failed to resolve: com.android.support:appcompat-v7:27.1.0
                   Install Repository and sync project
                   Show in File
                   Show in Project Structure dialog
    
    Error:(33, 13) Failed to resolve: com.android.support:percent:27.2.1
                   Install Repository and sync project
                   Show in File
                   Show in Project Structure dialog
  2. To resolve the above error, you need to do below two things.
  3. Add below content in the android studio project build.gradle file, because from android SDK version 26, it requires android support libraries to be downloaded from google maven repository, so add maven section with url “https://maven.google.com”.
    allprojects {
    
       repositories {
    
          jcenter()
    
          maven {
    
             url "https://maven.google.com"
    
          }
    
       }
    }
  4. Go to the google android support library package page.
  5. Search the not-compatible library by name ( for example input the name com.android.support:percent in the search box) and get the latest version ( for example com.android.support:percent:27.1.0 ) on the above page.
  6. Use the new version ( com.android.support:percent:27.1.0 ) in your build.gradle file. Click Sync Now or Try Again in android studio top right corner. After sync, the android project will build successfully.

1 thought on “How To Resolve Errors When Change SDK Level In Android Studio”

  1. how can i solve these error please?

    Failed to open zip file.
    Gradle’s dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
    Re-download dependencies and sync project (requires network)
    Re-download dependencies and sync project (requires network)

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.