在Build.Gradle同步期间发出查找属性

时间:2014-09-18 03:23:20

标签: android intellij-idea gradle android-gradle

错误:(83,0)无法找到属性' ANDROID_BUILD_SDK_VERSION'在com.android.build.gradle.LibraryExtension_Decorated@103ce86。

我错过了什么?我似乎无法解决这个问题。

**我的Build.Gradle **

   buildscript {
   repositories {
       mavenCentral()
       mavenLocal()
       maven {
            name 'maven.aviary.com'
            url uri("http://maven.aviary.com/repo/release")
       }
   }
    dependencies {
       classpath 'com.android.tools.build:gradle:0.9.+'
   }

}

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

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

allprojects {
   repositories {
       mavenCentral()
   }
}

我收到错误后指示的build.gradle

    apply plugin: 'android-library'

version aviarySdkVersionName + '.' + aviarySdkVersionCode

repositories {
    mavenCentral()
    mavenLocal()
    maven {
        name 'maven.aviary.com'
        url uri("http://maven.aviary.com/repo/release")
    }
}

ext {
    aviarySdkFlavor = "Production"
    aviarySdkBuildType = "Release"
    aviarySdkVersionCode = "0"
    aviarySdkVersionName = "0.0.0"
    aviarySdkPackageName = ""
}

task checkVersion << {
    if (!VERSION_NAME.equals(aviarySdkVersionName)) {
        println "$VERSION_NAME != $aviarySdkVersionName";
        throw new InvalidUserDataException("declared field VERSION_NAME must be eq to aviarySdkVersionName");
    }

    if (!GROUP.equals(aviarySdkPackageName)) {
        println "$GROUP != $aviarySdkPackageName";
        throw new InvalidUserDataException("field GROUP must be eq to aviarySdkPackageName");
    }
}

preBuild.dependsOn(checkVersion)

def all_tasks = gradle.startParameter.getTaskNames()

gradle.startParameter.getTaskNames().each { task ->

    println "current task: $task"

    for( single_task in all_tasks ) {
        if(all_tasks.size() == 1){
            println "single_task: $single_task"
            if (single_task.contains("Alpha")) {
                aviarySdkFlavor = "Alpha"
            } else if(single_task.contains("Beta")) {
                aviarySdkFlavor = "Beta"
            } else if(single_task.contains("Amazon")){
                aviarySdkFlavor = "Amazon"
            } else {
                aviarySdkFlavor = "Production"
            }

            if(single_task.contains("Debug")){
                aviarySdkBuildType = "Debug"
            } else {
                aviarySdkBuildType = "Release"
            }
        }
    }

    Properties props = new Properties()
    props.load(new FileInputStream("${rootProject.projectDir}/Aviary-SDK/gradle.properties"))

    aviarySdkPackageName = props.aviarySdkPackageName
    aviarySdkVersionName = props.aviarySdkVersionName
    aviarySdkVersionCode = props.aviarySdkVersionCode

    println "****************************************************"
    println "*             CONFIGURATION"
    println "* TASK: $task"
    println "* SDK_FLAVOR: $aviarySdkFlavor"
    println "* SDK_BUILD TYPE: $aviarySdkBuildType"
    println "* aviarySdkPackageName: $aviarySdkPackageName"
    println "* aviarySdkVersionName: $aviarySdkVersionName"
    println "* aviarySdkVersionCode: $aviarySdkVersionCode"
    println "*"
    println "****************************************************"
}

android {
    compileSdkVersion Integer.parseInt(ANDROID_BUILD_SDK_VERSION)
    buildToolsVersion ANDROID_BUILD_TOOLS_VERSION

    defaultConfig {
        minSdkVersion Integer.parseInt(ANDROID_BUILD_MIN_SDK_VERSION)
        targetSdkVersion Integer.parseInt(ANDROID_BUILD_TARGET_SDK_VERSION)

        versionCode Integer.parseInt(aviarySdkVersionCode)
        versionName VERSION_NAME

        applicationId aviarySdkPackageName

        buildConfigField "String", "SDK_PACKAGE_NAME", "\"${aviarySdkPackageName}\""
        buildConfigField "String", "SDK_VERSION_NAME", "\"${aviarySdkVersionName}\""
        buildConfigField "int", "SDK_VERSION_CODE", "${aviarySdkVersionCode}"
        buildConfigField "String", "SDK_FLAVOR", "\"${aviarySdkFlavor.toLowerCase()}\""
        buildConfigField "String", "SDK_BUILD_TYPE", "\"${aviarySdkBuildType.toLowerCase()}\""
        buildConfigField "boolean", "SDK_DEBUG", "${aviarySdkBuildType.toLowerCase().contains('debug')}"
    }

    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    packagingOptions {
    }
}

dependencies {
    println "(sdk) finalFlavor: $aviarySdkFlavor - $aviarySdkBuildType"

    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.aviary.android.feather.sdk:sdk-library:+'
}

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。

解决了我的问题是在根目录中的gradle.properties中定义这些键。

ANDROID_BUILD_TARGET_SDK_VERSION=19
ANDROID_BUILD_TOOLS_VERSION=19.1.0
ANDROID_BUILD_SDK_VERSION=19
ANDROID_BUILD_MIN_SDK_VERSION=10