简体   繁体   中英

Gradle version error while syncing project in Android studio

I am importing a very old android project which is not working in my latest version of Android studio when I tried to import , it gave me error straight away-

ERROR: Unsupported method: GradleProject.getProjectDirectory().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.

Thus I tried to upgrade the gradle version but it started to give other additional errors! My build.gradle files are as follows-

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/notice.txt'
    }

    defaultConfig {
        applicationId "com.abc.xyz"
        minSdkVersion 16
        targetSdkVersion 16
    }

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

dependencies {
    compile 'com.google.android.gms:play-services:7.3.0'
    compile 'com.android.support:support-v4:21.0.3'
    compile 'com.google.code.gson:gson:2.3.1'
    compile files('libs/volley.jar')
    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
    compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5'
    compile (group: 'org.apache.httpcomponents' , name: 'httpmime' , version: '4.3.6') {
        exclude module: 'org.apache.httpcomponents:httpclient'
    }
}

And project level build.gradle 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.2.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Since it is very old I failed several times trying to upgrade the versions of the support libraries but in the old code the old version of dependencies are used and it is impossible to refactor such a huge code base. what to do in this case! Any help is very much appreciated

My solution

 dependencies {
    classpath 'com.android.tools.build:gradle:4.0.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    classpath 'com.google.gms:google-services:4.2.0'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM