简体   繁体   English

无法设置 SDK:错误:模块“app”:平台“Google Inc.:Google APIs:21”未找到

[英]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.尝试将我的 SDK 更新到 23 但意识到我不准备处理所有新的弃用等,所以我在 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.我什至从头开始重新安装了 Android Studio,但我继续收到相同的警告,我的应用程序根本无法构建。 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')
}

You can use compileSdkVersion 21 instead of yours.您可以使用compileSdkVersion 21而不是您的。

    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'
        }
    }
}

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).如果您有一些遗留应用程序仍在使用 Google Map v1(例如),则建议将Google Inc.:Google APIs:21替换为21的(当前接受的)答案不适合。

If you are in this situation you REALLY need to compile against Google Inc.:Google APIs:21 or 23 etc...如果您处于这种情况,您真的需要针对Google Inc.:Google APIs:21或 23 等进行编译...

The solution here is to这里的解决方案是

Step 1步骤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.打开旧的SDK管理器界面,点击Android Studio SDK管理器下方的Launch Standalone SDK Manager链接,或通过命令行执行${ANDROID_SDK_DIR}/tools/android sdk直接打开。

Then locate Google APIs for the SDK version you need and install it:然后找到您需要的 SDK 版本的Google APIs并安装它:

SDK 管理器的屏幕截图

That package is hidden, for some reason, inside Android Studio and I expect Google will remove it at some point.由于某种原因,该包隐藏在 Android Studio 中,我希望 Google 会在某个时候将其删除。 Currently the SDK 24 one (Marshmallow) is available but the 25 (Nougat) is not, they may add it in the future, or not.目前 SDK 24 one (Marshmallow) 可用,但 25 (Nougat) 不可用,他们将来可能会添加,也可能不添加。 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.如果您遇到这种情况并且 Google 决定停止提供它,您将不得不使用地图 v2 重写功能。

Step 2第2步

Even after doing this and cleaning + gradle resync you'll get this error From Android Studio:即使在执行此操作并清理 + gradle resync 之后,您也会从 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 ).但是如果您尝试从命令行 ( ./gradlew assembleDebug ) 执行它,它将编译。

The reason has apparently something to do with the Android Studio embedded Java JRE.原因显然与 Android Studio 嵌入式 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).要使其在 Android Studio 中编译,请从 Android Studio 打开项目结构并为您在系统上安装的JDK提供自定义路径(您必须在计算机上安装 OpenJDK / OracleJDK)。

NOTE : it may be needed to navigate to the location instead of copying the path for Android studio to take the change.注意:可能需要导航到该位置,而不是复制 Android Studio 的路径以进行更改。 Do not pick the jre directory, pick the JDK (folder containing jre ).不要选择jre目录,选择 JDK(包含jre的文件夹)。

WARNING : this change is not specific to the project but will be applied to Android Studio itself and used on any other project.警告:此更改并非特定于项目,而是将应用于 Android Studio 本身并用于任何其他项目。

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.当它对我来说失败时,我下载了谷歌 API,就像@Daniel Segato 解释的那样,这是正确的做法,但我仍然一次又一次地收到消息。

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.我打开了模块的设置( Ctrl + Alt + Shift + S文件>项目结构),对于我的模块,我将编译 Sdk 版本选项更改为列表中的任何其他选项。 I resynchornized gradle and then changed the option back to Google APIs (API 23).我重新同步了 gradle,然后将选项改回了 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.在您在该对话框中更改它之前,Android Studio 不识别 SDK 真的非常非常讨厌。 But this only happened to me once.但这只发生在我身上一次。 Other times it was enough just to download the proper Google API and there you go!其他时候,只需下载适当的 Google API 就足够了! But this is nasty.但这很讨厌。

my problem was in my build.gradle: when I opened It was like this :我的问题出在我的 build.gradle 中:当我打开时它是这样的:

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删除'Google Inc.:Google APIs:21'并写 29 代替它

2.set 29 for targetSdkVersion 2.为targetSdkVersion设置29

RESULT:结果:

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.pixelnx.sam.allinone_room"
        minSdkVersion 21
        targetSdkVersion 29

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:原因:无法使用哈希字符串'Google Inc.:Google API:23'查找目标:E:\ AndroidStudio \ SDK - Error:Cause: failed to find target with hash string 'Google Inc.:Google APIs:23' in: E:\AndroidStudio\SDK 无法规范化文件'E:\ WorkSpace \ mapdemo \ app \ build \ intermediates \ mockable-Google Inc.:Google API:21.jar'的路径 - Could not normalize path for file 'E:\WorkSpace\mapdemo\app\build\intermediates\mockable-Google Inc.:Google APIs:21.jar' Firebase设置-错误:无法解决:com.google.firebase:firebase-core:12.0.1 - Firebase set up- error: Failed to resolve: com.google.firebase:firebase-core:12.0.1 带有URL的POST上的Google App Engine“未找到”错误 - Google App Engine “Not Found” error on POST with url 谷歌应用引擎:错误:NOT_FOUND - google app engine: Error: NOT_FOUND Google云端平台(应用引擎)SSL握手错误 - Google Cloud Platform (app engine) SSL Handshake error 如何在Android应用中处理/处理Firebase Cloud Messaging的数据有效负载(包括通知)? - How to handle/process Data payload (inc. Notification) of Firebase Cloud Messagingin an Android app? Google Drive SDK错误 - Google Drive SDK Error 设置Google App Engine应用程序有多困难? - How hard is it to set up a Google App Engine app? Android客户端和Google App Engine API - Android Client and Google App Engine APIs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM