How To Resolve Errors When Change SDK Level In Android Studio

When you add a new dependency library in android project, you may find it need 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.

We have introduced how to change android project sdk version in article How To Change Minimum Sdk Version In Android Studio. But when the new version is higher, you may encounter below errors in android studio.

Failed to find target with hash string’android-27′ in : C:\Users\Jerry\AppData\Local\Android\Sdk

change android studio sdk version in build gradle file

This means you do not have the required version related 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 android studio to download and install the new sdk files. When you see below popup window, that means the download and install successfully. Click Finish button to complete the install.

install not exist android sdk in local directory

2. Failed To Resolve Dependent Support Library Error.

After install the new sdk, you may find exist dependency library will not be compatible with new sdk like below error messages.

Error:(29, 13) Failed to resolve: com.android.support:appcompat-v7:27.1.0

Error:(33, 13) Failed to resolve: com.android.support:percent:27.2.1

exist dependency library do not compact with new android sdk version

To resolve above error, you need do below two things.

  1. Add below content in build.gradle file, because from android sdk version 26, it require 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"
            }
        }
    }
    

    add android support library download maven repository info

  2. Go to google android support library package page.
  3. Search the not compatible library by name and get the latest version in above page.
    find android support library latest version
  4. Use the new version 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.

(Visited 2,461 times, 6 visits today)
READ :   How To Debug Android SDK Source Code In Android Studio

Leave a Reply

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.