Could not find property 'android' on root

2019-08-10 00:51发布

问题:

i want to switch my project from eclipse to android studio with gradle support and get this failure message

Gradle 'Test' project refresh failed: Could not find property 'android' on root project 'Test'.

Could you help me? I have a project with a few sublibraries

This is my top level build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

apply plugin: android


allprojects {
    repositories {
        mavenCentral()
    }
}

compile project('Test')

回答1:

Don't put this in your top-level build file:

apply plugin: android

or this:

compile project('Test')

The apply plugin statement isn't necessary because there's no Android module in the root-level directory of projects with multi-module structure (which is the case for your project). And if you have dependencies, they need to go in a dependencies block in your module's build file.