Android Build Gradle给出complie()错误

时间:2016-10-21 13:57:19

标签: android gradle android-gradle build.gradle

我现在很长时间都面临这个错误..

Error:(24, 0) Could not find method compile() for arguments   
   [com.google.code.gson:gson:2.3] on object of type  
   org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

我的根build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        jcenter()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}



//apply plugin: 'com.android.application'  
//  
//android {  
//    compileSdkVersion 23  
//    buildToolsVersion '23.0.0'  
//}  

我的module/build.gradle

apply plugin: 'com.android.application'
android {

    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "com.example.zumoappname"
        minSdkVersion 7
        targetSdkVersion 17
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
       release {
         minifyEnabled false
         proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      }
    }

    repositories {
       flatDir {
          dirs 'aars'
      }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.google.guava:guava:18.0'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    compile 'com.microsoft.azure:azure-mobile-android:3.1.0'
    compile (group: 'com.microsoft.azure', name: 'azure-notifications-handler', version: '1.0.1', ext: 'jar')
}

请有人指点我正确的方向..

在此之前,我收到了“android方法”的类似错误..

我google了很多但没什么用处。 在此先感谢:)

1 个答案:

答案 0 :(得分:0)

您的文件似乎有问题。

结构应该是:

apply plugin: 'com.android.application'
android {

    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig { ... }
    buildTypes {
       release {...}
    }   
}

repositories { .. }

dependencies {
   //..
}

repositories块移到android块之外。