简体   繁体   中英

Google Glass, Gradle DSL method not found: 'android()'

I've been given a project to help with, but I cannot get it to work, and those who gave it to me are as stumped as I am. We're working on making an android software for Google Glass, using Android Studio 2.1.2. Also we've been setting up SDK and such.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
    }
}
allprojects {
    repositories {
        jcenter()
    }
}
android {
    compileSdkVersion 'Google Inc.:Glass Development Kit Preview:19'
    buildToolsVersion '23.0.1'
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}
dependencies {
}

That's the main build.gradle file. Then, in the app-folder, if that's important, this file lies. Also build.gradle.

apply plugin: 'com.android.application'
repositories {
jcenter()
}
android {
    compileSdkVersion 'Google Inc.:Glass Development Kit Preview:19'
    buildToolsVersion '23.0.1'
    final def config = defaultConfig {
        unimportant stuff
    }
    config
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildTypes {
        release {
            things
        }
    }
    dexOptions {
        hopefully unimportant
    }
    productFlavors {
    }
}
dependencies {
    a considerable amount
}

Now, I get the problem "Gradle DSL method not found: android()". There are more questions on here that ask about that. So, following the advice of those who answer, I attempted deleting the android and dependency things from the top gradle. I ended up with the following error. "Failed to set up SDK. Module 'app': platform 'Google Inc.:Glass Development Kit Preview:19' not found." This despite everything else is set up.

Now, note, the code as it looks obviously works, as it does for those who I got the code from. Something is very wrong on my end. I'm asking the good people of the internet, do you know what might be wrong?

You can only configure the android extension object for projects that you have applied the android plugin. Since you have not applied the android plugin to the root project, the android extension object does not exist in that project and therefore can't be configured. I'm guessing you meant to do the following in the main/root build.gradle

subprojects {
    if (plugins.hasPlugin('com.android.application')) {
        android {
            // common configuration for all android modules goes here
        }
    }
}

Another note on style, since this is in the root project:

allprojects {
    repositories {
        jcenter()
    }
}

You can remove this from the subproject

repositories {
    jcenter()
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM