Error:(52, 0) Gradle DSL method not found: 'сo

2019-05-03 23:20发布

问题:

I tried to use Quickblox API in my program by adding online maven dependencies. I'm using Android Studio.
When I tried to build my program, it shows the following error:

Error:(52, 0) Gradle DSL method not found: `сompile()` Possible causes:
  • The project 'Nanny Watch' may be using a version of Gradle that does not contain the method.
    Open Gradle wrapper file
  • The build file may be missing a Gradle plugin.
    Apply Gradle plugin
  • Here is the build.gradle(Project:NannyWatch2) file:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.5.0'
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
    
            jcenter()
        }
    }
    

    And here is the build.gradle(Module:App) file:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.2"
    
        defaultConfig {
            applicationId "com.example.user.nannywatch"
            minSdkVersion 16
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
            multiDexEnabled true
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        def qbSdkVersion = '2.5'
    
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'org.apache.commons:commons-lang3:3.4'
        compile 'net.schmizz:sshj:0.10.0'
        compile 'com.android.support:appcompat-v7:23.1.1'
        compile 'com.android.support:design:23.1.1'
        compile 'com.android.support:multidex:1.0.0'
        compile('vc908.stickers:stickerfactory:0.2.2@aar') {
            transitive = true;
        }
        compile 'com.google.android.gms:play-services-gcm:7.5.0'  
    
    // I tried using jar compile, but the method QBPushNotifications cannot be resolved
    // Therefore I tried to use the online repository
    
    //    compile files('src/main/java/com/example/user/nannywatch/jars/quickblox-android-sdk-chat-2.4.jar')
    //    compile files('src/main/java/com/example/user/nannywatch/jars/quickblox-android-sdk-content-2.4.jar')
    //    compile files('src/main/java/com/example/user/nannywatch/jars/quickblox-android-sdk-core-2.4.jar')
    //    compile files('src/main/java/com/example/user/nannywatch/jars/quickblox-android-sdk-customobjects-2.4.jar')
    //    compile files('src/main/java/com/example/user/nannywatch/jars/quickblox-android-sdk-location-2.4.jar')
    //    compile files('src/main/java/com/example/user/nannywatch/jars/quickblox-android-sdk-messages-2.4.jar')
    //    compile files('src/main/java/com/example/user/nannywatch/jars/quickblox-android-sdk-videochat-webrtc-2.4.jar')  
    
        сompile "com.quickblox:quickblox-android-sdk-core:$qbSdkVersion@aar"
        сompile ("com.quickblox:quickblox-android-sdk-chat:$qbSdkVersion@aar"){
            transitive=true
        }
        сompile "com.quickblox:quickblox-android-sdk-content:$qbSdkVersion@aar"
        сompile "com.quickblox:quickblox-android-sdk-messages:$qbSdkVersion@aar"
        сompile "com.quickblox:quickblox-android-sdk-customobjects:$qbSdkVersion@aar"
        сompile "com.quickblox:quickblox-android-sdk-location:$qbSdkVersion@aar"
        сompile "com.quickblox:quickblox-android-sdk-videochat-webrtc:$qbSdkVersion@aar"
    }
    

    There is also this warning: 'dependencies' cannot be applied to '(groovy.lang.Closure)' Image

    回答1:

    This is a very strange "bug". When you copied and pasted the Gradle lines from Quickblox, you copied a wrong ASCII code of the letter "c" in the word compile and Gradle would not recognize the word "compile".

    • the ASCII code of "c" copied from Quickblox site is 209 129
    • the ASCII code of "c" is 99

    You can try it yourself using this link: string to ASCII

    • regular letter → c
    • Quickblox letter → с

    Convert each letter and you will get a different ASCII code.

    So the solution is very simple, delete the letter c and write it yourself :)



    回答2:

    This can be a result of wrong Gradle version.

    There is used the following versions:

    • 'com.android.tools.build:gradle:1.3.0' for Gradle Android plugin
    • gradleVersion = '2.4' for Gradle

    https://github.com/QuickBlox/quickblox-android-sdk/blob/master/build.gradle