【问题标题】:android.compileSdkVersion is missingandroid.compileSdkVersion 丢失
【发布时间】:2014-08-08 11:56:52
【问题描述】:

根据设置 google play API - https://developer.android.com/google/play-services/setup.html,我正在使用 AndroidStudio 并尝试在我的应用上投放一些广告

Adter 我将项目与 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>

有什么想法吗?谢谢!

【问题讨论】:

  • 你能发布你的整个清单吗?
  • 好的,您缺少清单的关键部分。我将在下面发布答案。

标签: android gradle android-studio google-play-services


【解决方案1】:

您缺少清单的关键组件。您收到的 SDK 错误是因为编译器不知道在什么 SDK 级别编译您的应用程序 - 您缺少 &lt;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>

顶部的注意事项:packageandroid:versionCodeandroid:versionName 的部分。此外,在这些下方,以&lt;uses-sdk... 开头的整个部分都是必需的。

【讨论】:

  • 是的,我知道,但是当我使用 eclipse 时,它​​会自动为我完成,但在 AndroidStudio 上它从未这样做过,所以我认为没关系。但无论如何,我改变了我的清单(也在主要问题上更新了它)但我仍然得到同样的错误:错误:原因:android.compileSdkVersion is missing。
  • 有趣。在此处检查此问题/答案,看看是否有任何有用的信息,然后报告! stackoverflow.com/questions/22343013/…
  • 我刚刚发现我对 2 个 build.gradle 文件感到困惑,我更新了问题,因为现在我得到了一个不同的错误
  • 如果你在模块的 build.grade 文件中有它,你不需要在 manifest 文件中指定 sdk 版本,因为 gradle 在构建时将它生成到清单中。
【解决方案2】:

将此添加到您的 build.gradle:

android {
    compileSdkVersion 20
    buildToolsVersion '20.0.0'
}

【讨论】:

  • 添加到哪里重要吗?
  • 我发现您对 com.google.android.gms:play-services:5.0.77 有问题,请检查文件夹 /path/to/your/sdk/extras/google/m2repository/com/ google/android/gms/play-services/ 播放服务的正确版本。最后一个是 5.2.08,但是 play store 上仍然没有更新,我使用的是 5.0.89 版本
  • 所以只是将其更改为 5.0.89?
  • 尝试将播放服务版本更改为 5.0.89,如果再次出现错误,请尝试其他版本(检查 sdk 文件夹中的正确版本)
【解决方案3】:

我遇到了同样的问题,并通过以下方式解决了它: 在模块的build.gradle 文件中(通常在 app 中,而不是在根项目目录中)我设置

android {
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 19
        // your application version and id settings
    }

19 在哪里 - 是我在 Android SDK 管理器中完全加载的 SDK

(在 Studio 模块设置、PropertiesFlavors 选项卡中检查的值相同)。

所以,当您没有安装 8 个 API 时,您的问题可能是 minSdkVersion 8 值的原因。

【讨论】:

    【解决方案4】:

    我有同样的错误。

    在我的情况下,未安装包“Extras\Google Repository”。

    所以在 SDK Manager 中安装后问题就消失了。

    【讨论】:

      猜你喜欢
      • 2014-04-16
      • 2015-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-23
      • 1970-01-01
      • 2015-08-11
      • 2016-08-31
      相关资源
      最近更新 更多