我正在使用AndroidStudio,我试图在我的应用上放置一些广告,根据设置的google play API - https://developer.android.com/google/play-services/setup.html
Adter i将项目与grandle文件同步我收到此错误:
Error:Failed to find: com.google.android.gms:play-services:5.0.77
<a href="install.m2.repo">Install Repository and sync project</a><br><a href="openFile">Open File</a><br><a href="open.dependency.in.project.structure">Open in Project Structure dialog</a>
这是我的gradle.build:
apply plugin: 'com.android.application'
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.pachu.fartsounds"
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.google.android.gms:play-services:5.0.77'
}
我的宣言:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pachu.fartsounds">
<application
android:allowBackup="true"
android:icon="@drawable/fart_icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".FartActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
有什么想法吗?谢谢!
答案 0 :(得分:1)
您缺少清单的关键组件。您收到的SDK错误是因为编译器不知道在哪个SDK级别编译您的应用程序 - 您缺少<uses-sdk
。
虽然我们正在使用它,但您也缺少包名称,版本名称和版本代码。这些都是您应用的关键组件。这是一个结构良好的清单的例子:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exampleapp"
android:versionCode="2"
android:versionName="v0.2-Alpha" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.GET_TASKS" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.exampleapp.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:enabled="true" android:name="com.example.exampleapp.MyService" />
</application>
</manifest>
请注意顶部:阅读package
,android:versionCode
和android:versionName
的部分。而且,在这些之下,整个部分以<uses-sdk
开头......这些都是必需的。
答案 1 :(得分:1)
将此添加到build.gradle:
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
}
答案 2 :(得分:1)
我有同样的问题并在下一步修复:
在build.gradle
模块文件中(通常在 app 中,而不是在根项目目录中)我设置
android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 19
// your application version and id settings
}
其中 19 - 是和SDK我已经完全加载到 Android SDK Manager
(在Studio模块设置,属性和 Flavors 标签中检查相同的值)。
因此,当您没有安装8个API时,问题可能是minSdkVersion 8
值的原因。
答案 3 :(得分:0)
我遇到了同样的错误。
在我的情况下,包&#39; Extras \ Google Repository&#39;没安装。
因此,在SDK Manager中安装后,问题就消失了。