How you build a project using gradle?

2019-08-09 04:03发布

问题:

My build.gradle is given below.i have found this error.

Error:(15) A problem occurred evaluating root project 'smartwisher'.
> Could not find method android() for arguments [build_3rvo44ss7197kfip29gkh81rb6$_run_closure2@1d7a1869] on root project 'smartwisher'. 

This is build.gradle which i have in my android studio.

// Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.12.+'
        }
    }
    allprojects {
        repositories {
            mavenCentral()
        }
    }
    android {
        compileSdkVersion 19
        buildToolsVersion '20.0.0'
        defaultConfig {}
        productFlavors {
        }
    }
    dependencies {
    }

回答1:

You can't use the top level build.gradle to specify android configuration.

You have to move the android block in your module/build.gradle file.

Your folders.

root
  module
     build.gradle
  build.gradle
  settings.gradle

In your top-level file:

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

In your module/build.gradle:

apply plugin: 'android'

android {

}

dependencies {
}


回答2:

Your file is not easy to read here, you should put it in a code block. For what I saw you are missing at least one line :

apply plugin: 'android'


回答3:

You need to specify pluging applying in build.gradle:

apply plugin: 'android'