10
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')
}
Martin Erlic
  • 5,467
  • 22
  • 81
  • 153

4 Answers4

11

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'
        }
    }
}
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • Well, something's starting to work. Now I'm getting ``Error:Cause: failed to find target 21 : D:\Android\sdk1 Install missing platform(s) and sync project``, but it won't let me install it. Is there any way to manually download this from somewhere? I guess after reinstalling Android Studio it downloaded Sdk 23, but I really need to keep it at 21 for now. ``Ignoring unknown package filter 'android-21'Warning: The package filter removed all packages. There is nothing to install. Please consider trying to update again without a package filter.`` – Martin Erlic Dec 21 '15 at 13:59
  • did you `Clean-Rebuild-Restart-sync` in your project ? – IntelliJ Amiya Dec 21 '15 at 14:02
  • 1
    Yes and I keep getting the same issue. – Martin Erlic Dec 21 '15 at 14:05
  • Lol thanks but now I literally can't even open the project. This is ridiculous. – Martin Erlic Dec 21 '15 at 14:10
  • 1
    It worked! Thank you so much. Haha. What an ordeal. I spent a good few hours trying to get it up and running again. – Martin Erlic Dec 21 '15 at 14:18
  • 2
    You can actually (still) compile against the Google version of the API but you need to install those from the old SDK Manager (see my answer to this post) --- and this is the only real solution if you still need features from that version (ex. old maps v1) – Daniele Segato Oct 25 '16 at 14:34
8

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.

Daniele Segato
  • 12,314
  • 6
  • 62
  • 88
1

When it failed for me I downloaded Google API's, just as @Daniel Segato explains, which is the right thing to do, and still I got the message once and again and again.

Until I did this. I opened the module's settings (Ctrl + Alt + Shift + S or File > Project Structure) and, for my module, I changed the Compile Sdk Version option to any other from the list. I resynchornized gradle and then changed the option back to Google APIs (API 23). And then it worked! It's really really really nasty of Android Studio not to recognize the SDK until you change it in that dialog box. But this only happened to me once. Other times it was enough just to download the proper Google API and there you go! But this is nasty.

Juan José Melero Gómez
  • 2,742
  • 2
  • 19
  • 36
0

my problem was in my build.gradle ! when I opened It was like this :

android {
    compileSdkVersion 'Google Inc.:Google APIs:21'
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.pixelnx.sam.allinone_room"
        minSdkVersion 21
        targetSdkVersion 21

How fixed it ?!

  1. remove 'Google Inc.:Google APIs:21' and write 29 instead of it

2.set 29 for targetSdkVersion

RESULT :

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.pixelnx.sam.allinone_room"
        minSdkVersion 21
        targetSdkVersion 29
Sana Ebadi
  • 6,656
  • 2
  • 44
  • 44