Java 无法设置 SDK:错误:模块“应用程序”:平台“Google Inc.:Google APIs:21”未找到
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34397118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to set up SDK: Error:Module 'app': platform 'Google Inc.:Google APIs:21' not found
提问by Martin Erlic
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?
完全不知道为什么这不起作用。试图将我的 SDK 更新到 23,但意识到我没有准备好处理所有新的弃用等,所以我在 Mercurial 上恢复到旧版本。我实际上什么也没做,回归应该已经解决了所有问题。不幸的是,我无法连接我的应用程序并构建它。我什至从头开始重新安装了 Android Studio,但我继续收到相同的警告,我的应用程序根本无法构建。可能出什么问题了?
Here is my build gradle:
这是我的构建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')
}
采纳答案by IntelliJ Amiya
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'
}
}
}
回答by Daniele Segato
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 Inc.:Google APIs:21
用21
,如果你有一些遗留的应用程序仍然使用谷歌地图V1(例如)是不适合的。
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 Managerlink below the Android Studio SDK Manager or by executing ${ANDROID_SDK_DIR}/tools/android sdk
from command line to open it directly.
单击Android Studio SDK 管理器下方的Launch Standalone SDK Manager链接或${ANDROID_SDK_DIR}/tools/android sdk
从命令行执行直接打开它,打开旧的 SDK 管理器界面。
Then locate Google APIsfor the SDK version you need and install it:
然后找到您需要的 SDK 版本的Google APIs并安装它:
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.
由于某种原因,该软件包隐藏在 Android Studio 中,我希望 Google 会在某个时候将其删除。目前 SDK 24 one (Marshmallow) 可用,但 25 (Nougat) 不可用,他们可能会在未来添加或不添加。我们将不得不拭目以待。
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. To make it compile inside Android Studio open the Project Structurefrom Android Studio and provide a custom path for a JDKyou installed on your system (you must install a OpenJDK / OracleJDK on your computer).
原因显然与 Android Studio 嵌入式 Java JRE 有关。要使其在 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. Do not pick the jre
directory, pick the JDK (folder containing jre
).
注意:可能需要导航到该位置,而不是复制 Android Studio 的路径以进行更改。不要选择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 本身并用于任何其他项目。
回答by Juan José Melero Gómez
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.
当我失败时,我下载了 Google 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 Versionoption 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.
直到我做到了这一点。我打开了模块的设置(Ctrl + Alt + Shift + S
或File> Project Structure),对于我的模块,我将Compile Sdk Version选项更改为列表中的任何其他选项。我重新同步了 gradle,然后将该选项改回 Google API(API 23)。然后它起作用了!在您在该对话框中更改 SDK 之前,Android Studio 无法识别它,这真的非常令人讨厌。但这仅发生在我身上一次。其他时候,只需下载正确的 Google API 就足够了!但这很糟糕。
回答by sana ebadi
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 ?!
怎么修的?!
- remove
'Google Inc.:Google APIs:21'
and write 29 instead of it
- 删除
'Google Inc.:Google APIs:21'
并写入 29 而不是它
2.set 29 for targetSdkVersion
2.设置29 targetSdkVersion
RESULT :
结果 :
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.pixelnx.sam.allinone_room"
minSdkVersion 21
targetSdkVersion 29