【问题标题】:Error : cause android.compileSdkVersion is missing错误:导致 android.compileSdkVersion 丢失
【发布时间】:2014-04-16 02:02:54
【问题描述】:

我最近开始在 Android Studio 上工作。当我与 gradle 同步时,它给了我一个错误。

错误:原因:缺少 android.compileSdkVersion!

伙计们,这可能是什么原因,我已经安装了相同的 compileSDKVersion 和构建工具。我看到很多线程说确认您的系统中安装了相同的 sdk 版本,但在我的情况下它已经安装了。

build.gradle

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    sourceSets {
        instrumentTest.setRoot('src/test')
    }
}

【问题讨论】:

  • 你是在 root/build.gradle 还是 root/HelloWorld/build.gradle 中插入了 compileSdkVersion ?
  • 不,是这样的 pastebin.com/PfXhT2ae 如果需要,Android Studio 会添加这个

标签: android android-studio android-gradle-plugin


【解决方案1】:

我也遇到过这个问题,但不知道我的解决方案是否适合你。 我只是将这个脚本的位置:apply from: 'maven_push.gradle' 更改为 build.gradle 文件的底部,然后 BUILD SUCCESSFUL!

我在这里发布我的答案,你可以试试。:Building Android Studio project on Jenkins? android.compileSdkVersion is missing

【讨论】:

    【解决方案2】:

    我做到了。它适用于 Android Studio 0.4.6:

    /android_common.gradle

    android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"
    
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 19
    }
    
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    }
    

    /build.gradle

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.8.+'
        classpath 'com.github.jcandksolutions.gradle:android-unit-test:+'
    }
    
    allprojects {
    
        apply plugin: 'idea'
    
        repositories {
            mavenCentral()
            mavenLocal()
            maven {
                url 'https://oss.sonatype.org/content/repositories/snapshots/'
            }
        }
    }
    }
    
       def langLevel = 1.7
    
    idea {
    project {
        jdkName = langLevel
        languageLevel = langLevel
    }
      }
    

    /app/build.gradle

    apply plugin: 'android'
    apply from: "${rootDir}/android_common.gradle"
    
    android {
    defaultConfig {
        versionCode 1
        versionName "1.0"
        packageName "your.app.package.name"
    }
    
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
        compile 'com.squareup.dagger:dagger:1.2.1'
        compile 'com.squareup.dagger:dagger-compiler:1.2.1'
        compile 'com.j256.ormlite:ormlite-android:4.+'
        compile 'joda-time:joda-time:2.+'
    }
    
    sourceSets {
        instrumentTest.setRoot('src/test')
    }
    }
    
    apply plugin: 'android-unit-test'
    
    dependencies {
    instrumentTestCompile 'junit:junit:4.+'
    instrumentTestCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
    testCompile 'junit:junit:4.+'
    testCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
    }
    

    【讨论】:

    • 这个答案可能需要更新。它适用于旧版本的 Android Studio,仅列出代码,没有说明。我会看看我能做什么
    【解决方案3】:

    如果缺少某些内容,并且您已明确声明,则表示在定义之前已对其进行了查询。将查询(需要该变量的代码)移到较低的位置,或移到序列中较晚的位置,它将被修复。

    【讨论】:

      【解决方案4】:

      试试这个:

      apply plugin: 'android'
      apply from: "${rootDir}/android_common.gradle"
      

      将您的申请移至:"${rootDir}/android_common.gradle" 到最后几行

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-11-03
        • 1970-01-01
        • 2018-12-20
        • 2015-07-14
        • 2017-01-02
        • 1970-01-01
        • 1970-01-01
        • 2014-06-16
        相关资源
        最近更新 更多