Gradle DSL 메서드를 찾을 수 없음 : 'compile ()'


78

이 gradle 오류가 발생했습니다.

오류 : (9, 0) Gradle DSL 메서드를 찾을 수 없음 : 'compile ()'

비슷한 질문을 참조하려고했지만 작동하지 않았습니다.

Android gradle 빌드 오류 : (9, 0) Gradle DSL 메서드를 찾을 수 없음 : 'compile ()'.

Build.Gradle을 동기화 할 때 "Gradle DSL 메서드를 찾을 수 없음 : 'compile ()'"오류가 발생합니다.

지원되지 않는 Gradle DSL 메서드가 발견되었습니다 : 'compile ()'!

build.gradle코드는 여기

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
        compile 'com.android.support:appcompat-v7:20.+'
        compile 'com.google.android.gms:play-services:6.5.+'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

build.gradle(Module.app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
}

내 코드에 어떤 문제가 있습니까?

제 영어 죄송합니다.

감사합니다!


답변:


111

프로젝트 build.gradle파일 의 메모에서 알 수 있듯이 :

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

해당 gradle 파일에서 2 개의 컴파일 문을 제거합니다.

compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services:6.5.+'

그런 다음 다른 (모듈) build.gradle종속성을 다음과 같이 만드십시오 .

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.google.android.gms:play-services:6.5.+'
}

내 Android 프로젝트에 모듈이 없으면 어떻게 되나요?
arun8

com.android.support:support-compat:23.0.0 bt를 사용하고 있습니다. com.android.support:support-v4:23.0.0
10101010

36

IntelliJ Idea를 기반으로 Android 스튜디오를 사용하고 있으며 코드 래핑시기와 방법에 대한 설정을 변경했습니다. 또한 Gradle 파일을 무작위로 포맷하는 '자동 포맷'옵션이 있습니다. 따라서 다음과 같이 이어집니다.

    compile 'de.greenrobot:eventbus:2.4.0' compile 'com.jakewharton:butterknife:7.0.1'

그런 다음 Gradle은 두 번째 컴파일에 대한 compile ()을 찾지 못합니다. 한 줄에 하나의 종속성 만 작성할 수 있습니다.


이는이 오류가 @ 드류 발생할 수있는 이유는 또 다른 가능성이다
바토 - 베어 Tsyrenov

좋아요, 질문처럼 읽습니다. 싶어하지 않았이 삭제
드류

1
감사합니다. IDEA가 내 Gradle 파일의 형식을 변경하고 한 줄로 두 줄을 만들었습니다. 당신은 나를 위해 일한다고 대답합니다.
speedcell4

일부 추가 세부 사항은 여기 편리 할 것
크리스 네빌

@ChrisNevill 무슨 뜻이야?
Bato-Bair Tsyrenov

31

정말 어리석은 문제이며 해결책이 있습니다.

컴파일 문이 한 줄로 진행됨에 따라

compile "com.squareup.okhttp3:okhttp:$okHttpVersion"    compile "com.squareup.okhttp3:okhttp-urlconnection:$okHttpVersion"    compile "com.squareup.okhttp3:logging-interceptor:$okHttpVersion"    compile "com.google.code.gson:gson:$gsonVersion"

다음 줄로 변경하여 문제를 해결했습니다.

compile "com.squareup.okhttp3:okhttp:$okHttpVersion"
compile "com.squareup.okhttp3:okhttp-urlconnection:$okHttpVersion"
compile "com.squareup.okhttp3:logging-interceptor:$okHttpVersion"
compile "com.google.code.gson:gson:$gsonVersion"

도움이되기를 바랍니다. 감사합니다.


정확히이 ... 몇 가지 이유 뭔가를 한 줄에 내 컴파일 문을 당겨했다
크리스 네빌에게


나는 " '에 변화에 어느 정도 성공 했어
크리스 네빌

컴파일을 MyString + ''(즉 두 개의 빈 쉼표의의) : 나는 문자열을 사용했다 어디에서 일을 몇 가지 성공 했어
크리스 네빌

같은 문제에 직면했고 이것이 해결책입니다!
dmSherazi

8

build.gradle 파일을 확인하십시오 . 때로는 프로젝트 설정을 사용하여 현재 모듈에 모듈을 추가하고 현재 모듈의 build.gradle 이 손상되고 들여 쓰기가 손상 될 때 현재 build.gradle 을 확인하고 모든 컴파일 문이 있는지 확인하십시오. 새로운 라인으로 발행됩니다!


이것이 바로 모듈 설정에서 "서명"구성을 업데이트했을 때 발생한 일입니다.
Wahib Ul Haq

7

위에 이미 제공된 적절한 답변 외에도 자세한 설명을위한 그림 :

여기에 이미지 설명 입력

프로젝트에는 2 개의 build.gradle이 있습니다. 강조 표시된 것이 필요합니다 : build.gradle (모듈 : 앱)


2

프로젝트를 확인하십시오. 2 개의 build.gradle이 있습니다.

컴파일 라인을 다른 build.gradle로 이동하십시오.


0

애플리케이션 종속성은 앱-> build.gradle 파일에 포함되어야 합니다. 프로젝트-> build.gradle 파일에 없습니다.


0

간단한 실수는 포함되어 있지 않습니다도이 문제를 일으킬 수 있습니다 classpath에 대한 종속성을build.gradle(Module:app)


0

제 경우에는 dependencies블록 외부에 종속성 구현 줄이 있었기 때문에이 오류가 발생했습니다 . 이 같은:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    ...
  }

implementation 'androidx.media:media:1.1.0'

모든 구현 호출은 종속성 블록 내에 정의되어야합니다.그것은 간단한 수정입니다.

나는 이것이 누군가를 돕기를 바랍니다.

메리 코딩!

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.