无法在对象上找到参数 [directory 'libs'] 的方法compile()

Hah*_*ehe 3 android gradle android-gradle-plugin

我尝试获取 GetHttpResponse 这是下面的代码。我尝试过项目重新同步但无济于事。

完整错误:在 org.gradle.api.internal.artifacts.dsl.dependency.DefaultDependencyHandler 类型的对象上找不到参数 [directory 'libs'] 的compile()方法。

   configure(':app') {
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.2'
            compile fileTree(dir: 'libs', include: ['*.jar'])
            testCompile 'junit:junit:4.12'
            compile 'com.android.support:appcompat-v7:23.0.1'
            compile 'com.android.support:design:23.0.1'
            compile 'org.apache.httpcomponents:httpcore:4.4.1'
            compile 'org.apache.httpcomponents:httpclient:4.5'
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是我的 gradle 文件

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "itp361.nyp"
        minSdkVersion 23
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        useLibrary 'org.apache.http.legacy'
    }
Run Code Online (Sandbox Code Playgroud)

这是我的 gradle 应用程序文件。我搜索了许多不同的问题并应用了它,但它仍然提示我错误。我还将可执行 jar 'org.arpache.http.leagcy' 添加到 C:\Users\user\Downloads\NYP\NYP\app\libs

Mur*_*göz 5

阅读注释。

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Run Code Online (Sandbox Code Playgroud)

你在项目中build.gradle。您必须将依赖项放入模块中build.gradle。这是您发布的第二个片段。