错误:导致android.compileSdkVersion丢失

N S*_*rma 14 android android-studio android-gradle-plugin

我最近开始在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')
    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在此输入图像描述

cod*_*zjx 14

我也遇到了这个问题,但我不知道我的解决方案是否适合你.我只是改变了这个脚本的位置:apply from: 'maven_push.gradle'在build.gradle文件的底部,并且BUILD SUCCESSFUL!

我在这里发布我的答案,你可以尝试一下:在Jenkins上构建Android Studio项目?android.compileSdkVersion丢失了


Mar*_*ari 3

我这样做了。它适用于 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
}
}
Run Code Online (Sandbox Code Playgroud)

/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
}
  }
Run Code Online (Sandbox Code Playgroud)

/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'
}
Run Code Online (Sandbox Code Playgroud)