Programming

'(groovy.lang.Closure)'에 '종속성'을 적용 할 수 없습니다

procodes 2020. 7. 16. 20:09
반응형

'(groovy.lang.Closure)'에 '종속성'을 적용 할 수 없습니다


이 오류를 해결할 수 없습니다 :

dependencies cannot be applied to '(groovy.lang.Closure)

이것은 내 gradle 파일입니다.

buildscript {
     repositories {
         maven { url 'http://download.crashlytics.com/maven' }
     }

     dependencies {
         classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
     }
 }
apply plugin: 'android'
apply plugin: 'crashlytics'

repositories {
   maven { url 'http://download.crashlytics.com/maven' }
}

dependencies {
    compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':FRNDzTER_core')
    compile project(':cropper')
    compile project(':stickyListHeaders')
    compile "com.nostra13.universalimageloader:universal-image-loader:${rootProject.universalImageLoaderVersion}"
    compile "com.google.android.gms:play-    services:${rootProject.googlePlayServicesVersion}"
    compile "de.keyboardsurfer.android.widget:crouton:${rootProject.croutonVersion}"
    compile "com.nineoldandroids:library:${rootProject.nineoldandroidsVersion}"
    compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
    compile 'com.crashlytics.android:crashlytics:1.+'
}

android{
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion
    defaultConfig {
        minSdkVersion rootProject.minSdkVersion
        targetSdkVersion rootProject.targetSdkVersion
        versionCode rootProject.versionCode
        versionName rootProject.versionName
    } 
    buildTypes {
        release {
            debuggable rootProject.prodDebug
            proguardFile 'proguard.cfg'
        }
    }

    dependencies {
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    lintOptions {
        abortOnError false
    }
 }

Android Studio에서 생성하는 내용에 따라 최상위 프로젝트 파일 build.gradle과 앱용 파일이 있어야합니다 build.gradle.

최상위 :

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven { url 'http://download.crashlytics.com/maven' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'http://download.crashlytics.com/maven' }
    }
}

응용 프로그램 수준 :

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

android{
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion
    defaultConfig {
        minSdkVersion rootProject.minSdkVersion
        targetSdkVersion rootProject.targetSdkVersion
        versionCode rootProject.versionCode
        versionName rootProject.versionName
    } 
    buildTypes {
        release {
            debuggable rootProject.prodDebug
            proguardFile 'proguard.cfg'
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    lintOptions {
        abortOnError false
    }
 }     `

dependencies {
    compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':FRNDzTER_core')
    compile project(':cropper')
    compile project(':stickyListHeaders')
    compile "com.nostra13.universalimageloader:universal-image-          l                        loader:${rootProject.universalImageLoaderVersion}"
    compile "com.google.android.gms:play-    services:${rootProject.googlePlayServicesVersion}"
    compile "   "de.keyboardsurfer.android.widget:crouton:${rootProject.croutonVersion}"
    compile "com.nineoldandroids:library:${rootProject.nineoldandroidsVersion}"
    compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
    compile 'com.crashlytics.android:crashlytics:1.+'
}

그러나 그 모든 것이 없어도 문제는 플러그인 구성 dependencies내에 있다는 것 android입니다.

android {
    dependencies {
    }
}

dependencies블록을 제거하십시오 .

편집 : 또한 최신 Android Studio 에서이 오류가 발생하기 시작했습니다. 최신 버전의 Gradle 플러그인과 compileSdkVersion 22를 추가하기 만하면됩니다.

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}

환경 설정으로 이동하여 "기본 gradle 래퍼 사용"을 선택한 다음 프로젝트를 다시 빌드하십시오. 그것은 나를 위해 잘 작동했습니다 :여기에 이미지 설명을 입력하십시오


이동

윈도우

파일-> 설정-> 빌드, 실행, 배포-> 빌드 도구-> Gradle

환경 설정-> 빌드, 실행, 배포-> 빌드 도구-> Gradle

기본 gradle 래퍼 사용을 선택하십시오.


내 문제는 전체 build.setting 파일이 cannot be applied to '(groovy.lang.Closure)'특정 변수에서 발생하는 대신 경고 메시지 로 채워져 있다는 것입니다.

나는 다른 사람들이 제공 한 모든 솔루션을 시도했지만 그중 어느 것도 나를 위해 작동하지 않습니다. 나는이 단계를 끝내고 매력처럼 작동합니다. 같은 문제가 발생하면 시도해보십시오.

  1. 파일 열기 및 편집 : yourproject/gradle/wrapper/gradle-wrapper.properties. 아래 이미지와 같이 콘텐츠를 편집하여 gradle 배포 버전을 업데이트 한 다음 저장하십시오.
  2. 이 폴더를 삭제하십시오 : yourproject/.gradle.
  3. 를 클릭하십시오 Sync project with gradle files.

여기에 이미지 설명을 입력하십시오


이미 "기본 gradle wrapper"를 사용하고 있는데 도움이되지 않는 경우 :

In Menu click: File -> Invalidate Caches / Restart...

2 단계로도 도움이되지 않는 경우 :

1) Delete ".gradle" folder (and "build" folder if you have it already)

2) In Menu click: File -> Invalidate Caches / Restart...

다시 시작하면 경고가 사라집니다.

(나에게 그것은 Android Studio와 IntelliJ Idea에서 효과가있었습니다)


gradle홈 디렉토리가 잘못되었다는 경고를 발견했을 때 다른 답변 중 하나를 시도하기 위해 환경 설정으로 이동했습니다 . 그래서 파일 브라우저를 열고 최신 gradle버전을 선택했는데 모든 오류가 사라졌습니다. 이미지는 아래와 같습니다.

여기에 이미지 설명을 입력하십시오


나는 당신에게 문제가 경고를주는 코드와 전혀 관련이 없다는 것을 확신합니다. 아마도 proguard 파일 일 것입니다. 내 코드에 다음과 같은 경고가 표시되었습니다.

buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

을 주석으로 처리 runProguard false하면 모든 문제가 사라지고 그림으로 이동합니다. :)


안드로이드 스튜디오 2.2에서도 같은 문제가 있습니다.

실물:

android {
...
}

dependencies {
...
}

이동 dependenciesandroid:

android {
...
   dependencies {
   ...
   }
}

캐시를 무효화하고 다시 시작하여 Android Studio의 문제를 해결했습니다.

File-> Invalidate Caches / Restart..

여기에 이미지 설명을 입력하십시오


  1. Close the project (File / Close project),
  2. Select “Open an existing Android Studio project” on the start menu and select the folder that contains your Android project.

This work for me.


Gradle files can be made explicit in several places to avoid such errors. E.g. Change

configurations {

to

project.configurations {

or

task {
    description 'foo'

to

task {
    setDescription 'foo'

To fix the issue simply close the project, then select “Open an existing Android Studio project” on the start menu and select the folder that contains your Android project. Beware, select the folder, not the .iml project file.


Cut and then paste the "buildTypes" at the same place in "android" section and Re-Sync (refresh) Project


Kotlin 프로젝트의 IntelliJ에서 이와 비슷한 문제가 발생했습니다. 문제는 내 프로젝트에서 JDK 8을 사용하도록 설정되었지만 언어 및 API 버전이 어떻게 든 1.3으로 설정되었다는 것 같습니다. 프로젝트 환경 설정> 패싯을 참조하십시오. 필자의 경우 "프로젝트 설정 사용"을 선택했지만 패싯별로 수동으로 설정해도 효과가 있습니다.


gradle 2.10 으로이 문제를 해결했습니다.

여기에서 다운로드하십시오 : http://gradle.org/gradle-download/

그리고 다음과 같이 로컬 gradle 배포를 설정하십시오.

여기에 표시된대로

참고 URL : https://stackoverflow.com/questions/29769988/dependencies-cannot-be-applied-to-groovy-lang-closure

반응형