Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to set up SDK: Error:Module 'app': platform 'Google Inc.:Google APIs:21' not found

Failed to set up SDK: Error:Module 'app': platform 'Google Inc.:Google APIs:21' not found.

At a complete loss as to why this isn't working. Attempted to update my SDK to 23 but realized I wasn't prepared to deal with all the new deprecations, etc., so I reverted to an older version on Mercurial. I've done literally nothing else, and the reversion should have solved everything. Unfortunately, I'm stuck unable to connect my app and build it. I've even reinstalled Android Studio from scratch, but I continue to receive the same warning and my app won't build at all. What could possibly be going wrong?

Here is my build gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'Google Inc.:Google APIs:21'
    buildToolsVersion '21.1.2'

    defaultConfig {
        applicationId "com.elgami.customizer"
        minSdkVersion 14
        targetSdkVersion 21
    }

    buildTypes {
        release {
            minifyEnabled false
            //runProguard false
            //proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

repositories {
    mavenCentral()
    maven { url "https://jitpack.io" }
}

dependencies {
    compile 'com.ogaclejapan.smarttablayout:library:1.5.0@aar'
    compile 'com.github.antonyt:InfiniteViewPager:v1.0.0'
    compile 'com.android.support:appcompat-v7:22.2.0'
    // recyclerview
    compile 'com.android.support:recyclerview-v7:23.1.1'
    // google analytics
    compile 'com.google.android.gms:play-services-analytics:8.3.0'
    // pager sliding strip
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    // http library (for using beanstream REST)
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
    // amaazon S3 uploads
    compile 'com.amazonaws:aws-android-sdk-s3:2.1.+'
    // paypal purchasing
    compile files('libs/PayPalAndroidSDK-2.7.1.jar')
    // Module dependency on ParseLoginUI library sources
    compile project(':ParseLoginUI')
    // Parse libs
    compile files('libs/ParseCrashReporting-1.9.2.jar')
    compile files('libs/Parse-1.9.1.jar')
    compile files('libs/ParseFacebookUtilsV4-1.9.1.jar')
    // android support v4
    compile files('libs/android-support-v4.jar')
    // facebook SDK
    compile 'com.facebook.android:facebook-android-sdk:4.1.0'
    //butterknife
    compile 'com.jakewharton:butterknife:6.1.0'
    // Subsampling-scale-image-view (for templating)
    //compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.1.4'
    compile files('libs/AppRater.jar')
}
like image 403
Martin Erlic Avatar asked Dec 21 '15 13:12

Martin Erlic


People also ask

How do I fix Android SDK is missing or corrupted?

Quick fix: Go to the Tools –> SDK manager –> SDK tools. Deselect Hide obsolete packages option on the right bottom and further install Android SDK Tools(obsolete).

Which SDK for Android 11?

For the best development experience with the Android 11 SDK, use Android Studio 4.2 or higher.

How do I sync my Android SDK?

To do this click on File > you will get to see the option as Sync Project With Gradle files option click on that option and sync your project. On successful sync of your project, your SDK location is set perfectly and now you are good to go in developing Android Applications.


2 Answers

You can use compileSdkVersion 21 instead of yours .

    android {
    compileSdkVersion 21
    buildToolsVersion '21.1.2'

    defaultConfig {
        applicationId "com.elgami.customizer"
        minSdkVersion 14
        targetSdkVersion 21
    }

    buildTypes {
        release {
            minifyEnabled false
            //runProguard false
            //proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}
like image 57
IntelliJ Amiya Avatar answered Oct 05 '22 18:10

IntelliJ Amiya


The (currently accepted) answer that suggest replacing Google Inc.:Google APIs:21 with 21 is NOT suitable if you have some legacy app still using Google Map v1 (for example).

If you are in this situation you REALLY need to compile against Google Inc.:Google APIs:21 or 23 etc...

The solution here is to

Step 1

Open the old SDK manager interface clicking the Launch Standalone SDK Manager link below the Android Studio SDK Manager or by executing ${ANDROID_SDK_DIR}/tools/android sdk from command line to open it directly.

Then locate Google APIs for the SDK version you need and install it:

screenshot of the SDK Manager

That package is hidden, for some reason, inside Android Studio and I expect Google will remove it at some point. Currently the SDK 24 one (Marshmallow) is available but the 25 (Nougat) is not, they may add it in the future, or not. We will have to wait and see.

If you are in this situation and Google decide to stop providing it you'll have to rewrite the functionality using maps v2.

Step 2

Even after doing this and cleaning + gradle resync you'll get this error From Android Studio:

Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.

But it will compile if you try to do it from the command line (./gradlew assembleDebug).

The reason has apparently something to do with the Android Studio embedded Java JRE. To make it compile inside Android Studio open the Project Structure from Android Studio and provide a custom path for a JDK you installed on your system (you must install a OpenJDK / OracleJDK on your computer).

NOTE: it may be needed to navigate to the location instead of copying the path for Android studio to take the change. Do not pick the jre directory, pick the JDK (folder containing jre).

WARNING: this change is not specific to the project but will be applied to Android Studio itself and used on any other project.

like image 27
Daniele Segato Avatar answered Oct 05 '22 19:10

Daniele Segato