【问题标题】:Failed to set up SDK: Error:Module 'app': platform 'Google Inc.:Google APIs:21' not found未能设置 SDK:错误:模块“应用程序”:未找到平台“Google Inc.:Google APIs:21”
【发布时间】:2016-03-27 14:41:50
【问题描述】:
Failed to set up SDK: Error:Module 'app': platform 'Google Inc.:Google APIs:21' not found.

完全不知道为什么这不起作用。尝试将我的 SDK 更新到 23,但意识到我还没有准备好处理所有新的弃用等,所以我在 Mercurial 上恢复到旧版本。我实际上什么也没做,回归应该解决了一切。不幸的是,我无法连接我的应用程序并构建它。我什至从头开始重新安装了 Android Studio,但我仍然收到同样的警告,而且我的应用程序根本无法构建。可能出了什么问题?

这是我的构建 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')
}

【问题讨论】:

    标签: java android gradle sdk


    【解决方案1】:

    我的问题出在我的 build.gradle 中!我打开的时候是这样的:

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

    如何修复它?!

    1. 删除'Google Inc.:Google APIs:21'并写29而不是它

    2.为targetSdkVersion设置29

    结果:

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

    【讨论】:

      【解决方案2】:

      当它失败时,我下载了 Google API,正如 @Daniel Segato 解释的那样,这是正确的做法,但我仍然一次又一次地收到消息。

      直到我这样做。我打开了模块的设置(Ctrl + Alt + Shift + SFile > Project Structure),对于我的模块,我将 Compile Sdk Version 选项更改为列表中的任何其他内容。我重新同步了 gradle,然后将选项改回 Google API(API 23)。然后它起作用了!在您在该对话框中更改它之前,Android Studio 无法识别 SDK 真的非常讨厌。但这只发生在我身上一次。其他时候只需下载正确的 Google API 就足够了!但这很讨厌。

      【讨论】:

        【解决方案3】:

        建议将Google Inc.:Google APIs:21 替换为21 的(当前接受的)答案不适合如果您有一些仍在使用Google Map v1 的旧版应用程序(例如)。

        如果您遇到这种情况,您真的需要针对 Google Inc.:Google APIs:21 或 23 等进行编译...

        这里的解决方案是

        第 1 步

        点击Android Studio SDK Manager下方的Launch Standalone SDK Manager链接或从命令行执行${ANDROID_SDK_DIR}/tools/android sdk直接打开旧的SDK管理器界面。

        然后找到您需要的 SDK 版本的 Google APIs 并安装它:

        由于某种原因,该包隐藏在 Android Studio 中,我希望 Google 会在某个时候将其删除。目前 SDK 24 one (Marshmallow) 可用,但 25 (Nougat) 不可用,他们可能会在未来添加或不添加。我们将不得不拭目以待。

        如果您处于这种情况并且 Google 决定停止提供它,您将不得不使用 maps v2 重写该功能。

        第 2 步

        即使在执行此操作并清理 + 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.
        

        但如果您尝试从命令行 (./gradlew assembleDebug) 执行此操作,它将编译。

        原因显然与 Android Studio 嵌入式 Java JRE 有关。 要使其在 Android Studio 中编译,请从 Android Studio 打开 Project Structure 并为您在系统上安装的 JDK 提供自定义路径(您必须在你的电脑)。

        注意:可能需要导航到该位置,而不是复制路径以便 Android Studio 进行更改。不要选择jre目录,选择JDK(包含jre的文件夹)。

        警告:此更改并非特定于项目,而是将应用于 Android Studio 本身并用于任何其他项目。

        【讨论】:

          【解决方案4】:

          您可以使用 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'
                  }
              }
          }
          

          【讨论】:

          • 嗯,有些东西开始起作用了。现在我得到Error:Cause: failed to find target 21 : D:\Android\sdk1 <a href="install.android.platform">Install missing platform(s) and sync project</a>,但它不会让我安装它。有没有办法从某个地方手动下载这个?我猜在重新安装 Android Studio 后它下载了 Sdk 23,但我现在真的需要将它保持在 21。 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.
          • 你在你的项目中Clean-Rebuild-Restart-sync了吗?
          • 是的,我一直遇到同样的问题。
          • 成功了!太感谢了。哈哈。多么严峻的考验。我花了好几个小时试图让它重新启动并运行。
          • 您实际上(仍然)可以针对 API 的 Google 版本进行编译,但您需要从旧的 SDK 管理器安装它们(请参阅我对这篇文章的回答)——这是唯一真正的如果您仍然需要该版本的功能(例如旧地图 v1)
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-05-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多