简体   繁体   English

Google Glass,找不到Gradle DSL方法:“ android()”

[英]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. 我们正在使用Android Studio 2.1.2为Google Glass开发一个android软件。 Also we've been setting up SDK and such. 另外,我们一直在设置SDK等。

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. 那是主要的build.gradle文件。 Then, in the app-folder, if that's important, this file lies. 然后,在应用程序文件夹中,如果这很重要,则此文件位于。 Also build.gradle. 也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()". 现在,出现问题“找不到Gradle DSL方法: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. 因此,按照回答者的建议,我尝试从最重要的位置删除android和依赖项。 I ended up with the following error. 我最终遇到以下错误。 "Failed to set up SDK. Module 'app': platform 'Google Inc.:Glass Development Kit Preview:19' not found." “未能设置SDK。模块'app':平台'Google Inc.:Glass Development Kit Preview:19'未找到。” 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. 您只能为已应用android插件的项目配置android扩展对象。 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. 由于您尚未将android插件应用于根项目,因此该项目中不存在android扩展对象,因此无法对其进行配置。 I'm guessing you meant to do the following in the main/root build.gradle 我猜你打算在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()
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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