将jar添加到Gradle

Tpo*_*6oH 2 android gradle build.gradle

这是我的build.gradle

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

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 18
    }
}

dependencies {
    compile 'com.android.support:support-v4:+'
    compile file 'volley.jar'
}
Run Code Online (Sandbox Code Playgroud)

当我尝试构建它时,此错误会出现:

Gradle: A problem occurred evaluating project ':Name'.
> No such property: file for class:     org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler
Run Code Online (Sandbox Code Playgroud)

如果我尝试,会出现相同的错误

gradle clean
Run Code Online (Sandbox Code Playgroud)

在项目目录中

Ser*_*kyi 5

这是错字 compile files

dependencies {
    compile files('volley.jar')
}
Run Code Online (Sandbox Code Playgroud)

  • 导致异常的原因是缺少括号,在这种情况下不能省略(因为它们已经为`compile`省略了).然而,在这里使用`files`而不是`file`很重要. (3认同)