找不到参数[directory'libs']

时间:2017-06-27 15:04:32

标签: android gradle android-gradle build.gradle

我将项目导入到Android工作室的工作区中,项目的文件结构似乎没有正确的状态,如图1所示。

此外,当我尝试构建和编译项目时,我收到以下错误:

Error:(20, 0) Could not find method compile() for arguments [directory 'libs'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
<a href="openFile:C:\Users\xxx\AndroidStudioProjects\MAN\build.gradle">Open File</a>

同样在项目中,build.gradle(项目)存在两次,build.gradle(app)存在一次,如image-2所示

请查看下面的gradle文件,请让我知道如何更正此错误以及我收到错误的原因。

的build.gradle(APP)

apply plugin: 'com.android.application'
apply plugin: 'android-apt'

def AAVersion = '3.2' // '4.2.0'

dependencies {
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
}

apt {
arguments {
    androidManifestFile variant.outputs[0].processResources.manifestFile
    resourcePackageName 'eu.man.m24wsapp'
}
}

android {
compileSdkVersion 25
buildToolsVersion '25.0.2'

defaultConfig {
    applicationId "eu.man.m24wsapp"

    targetSdkVersion 25
    minSdkVersion 10

    versionCode 1
    versionName "1.1.18"
}

signingConfigs {
    release {
        storeFile file("../wsapp.keystore")
        storePassword "7s5zhgknsIXxHgw"
        keyAlias "man_mobile24"
        keyPassword "manmobile242014"
    }
}

lintOptions {
    checkReleaseBuilds false
    // Or, if you prefer, you can continue to check for errors in release builds,
    // but continue the build even when errors are found:
    abortOnError false
}

buildTypes {
    release {
        minifyEnabled false // 15.05.2017 avk, enables/disables proguard
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release

        applicationVariants.all { variant ->
            variant.outputs.each { output ->
                def name = output.outputFile.name.replace("app", "Man");
                name = name.replace(".apk", "-" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk");
                output.outputFile = new File(output.outputFile.parent, name)
            }
        }
    }
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':appcompat')
compile project(':securepreferences')
compile 'com.android.support:support-v4:25.2.0' // .0.1

compile 'com.google.android.gms:play-services:4.3.23'
//    compile 'com.google.android.gms:play-services-maps:10.0.1'
//    compile 'com.google.android.gms:play-services-location:10.0.1'

// AVK 05.02.2017 compile 'com.github.chrisbanes.photoview:library:1.2.2'
compile 'com.github.chrisbanes.photoview:library:1.2.4'
compile 'com.google.code.gson:gson:2.7' // 2.4

// AVK 5.2.2017 compile 'com.squareup:otto:1.3.6'
compile 'com.squareup:otto:1.3.8'

// AVK 5.2.2017 compile 'com.squareup.okhttp:okhttp:1.5.4'
// AVK 5.2.2017 compile 'com.squareup.okhttp:okhttp:2.5.0'
// AVK 5.2.2017 compile 'com.squareup.okhttp:okhttp:2.6.0' // oder
compile 'com.squareup.okhttp:okhttp:2.2.0' // 7.5' // oder
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0' // 7.5' // oder
// https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
// AVK 5.2.2017 compile group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.6.0'

compile 'com.squareup.picasso:picasso:2.4.0'
//compile 'com.squareup.picasso:picasso:2.2.0'
// AVK 5.3.2017 compile 'com.squareup.picasso:picasso:2.4.0'

// AVK 3.2.2017 compile 'com.squareup.retrofit:retrofit:1.5.1'
// AVK 3.2.2017 compile group: 'com.squareup.retrofit', name: 'retrofit', version: '1.9.0'
compile 'com.squareup.retrofit:retrofit:1.8.0'
// AVK 5.2.2017 compile 'com.squareup.retrofit2:retrofit:2.1.0'

}

**build.gradle(project)**:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
    jcenter()
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.3.0'
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7' // 1.8?
}
}
allprojects {
repositories {
    jcenter()
    mavenCentral()
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('app/libs/android-viewbadger.jar')
compile files('app/libs/iDappsImagesLib_v0.2.jar')
compile files('app/libs/iDappsToolsLib_v0.1.jar')
compile files('gradle/wrapper/gradle-wrapper.jar')
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
dexOptions {
    incremental true
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}
}

图片-1

enter image description here

图片-2

enter image description here

图片3项目属性

enter image description here

image-4 gradle path

enter image description here

1 个答案:

答案 0 :(得分:0)

将引用的阻止从build.gradle(project)移至build.gradle(app)compileandroid来自application插件

<强>的build.gradle(项目)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
    jcenter()
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.3.0'
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7' // 1.8?
}
}
allprojects {
repositories {
    jcenter()
    mavenCentral()
}
}

<强>的build.gradle(APP)

 dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('app/libs/android-viewbadger.jar')
    compile files('app/libs/iDappsImagesLib_v0.2.jar')
    compile files('app/libs/iDappsToolsLib_v0.1.jar')
    compile files('gradle/wrapper/gradle-wrapper.jar')
 }
 android {
     compileSdkVersion 25
     buildToolsVersion '25.0.2'
     dexOptions {
     incremental true
 }

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}