如何修复Gradle同步失败“找不到ID'com.android.application'的插件”?

时间:2017-11-02 08:22:01

标签: java android android-studio gradle android-gradle

我正在使用 Android studio 1.3.2 ,Java jdk1.8.0_111

我在Android工作室日志 idea.log

中找到了
org.gradle.tooling.BuildException: Could not run build action using Gradle distribution 

'https://services.gradle.org/distributions/gradle-3.3-all.zip'.

=

Caused by: org.gradle.internal.exceptions.LocationAwareException: Build file 'D:\Projects\SampleApplication\app\build.gradle' line: 1
   A problem occurred evaluating project ':app'.

应用 build.gradle

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

repositories {
    mavenCentral()
}
}

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
}
}

ext {
   supportlib_version = '26.0.2'
   gps_version = '11.2.0'
 }

//Ensure that all dependencies use the same version of the Android Support 
  library
 subprojects {
project.configurations.all {
    resolutionStrategy.eachDependency { details ->
        if (details.requested.group == 'com.android.support'
                && !details.requested.name.contains('multidex')) {
            details.useVersion "$supportlib_version"
        }
        if (details.requested.group == 'com.google.android.gms'
                && !details.requested.name.contains('multidex')) {
            details.useVersion "$gps_version"
        }
    }
}
}

allprojects {
repositories {
    jcenter()
}
}

应用\的build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion '26.0.1'
defaultConfig {
    applicationId "com.myapp"
    minSdkVersion 16
    targetSdkVersion 26
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    //Optionally configure your OneSignal IDs below
    manifestPlaceholders = [manifestApplicationId: "${applicationId}",
                            onesignal_app_id: "",
                            onesignal_google_project_number: ""]
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
dexOptions {
    jumboMode true
}
 }

repositories {
   flatDir {
    dirs 'libs'
  }
maven {
    url "https://jitpack.io"
   }
   jcenter();
 }

  dependencies {
    compile 'com.devbrackets.android:exomedia:4.0.3' //TV
    compile 'com.cleveroad:audiovisualization:1.0.0' //Radio
    compile 'com.squareup.okhttp3:okhttp:3.3.1' //WC
    compile 'org.jsoup:jsoup:1.8.3'
    compile 'com.onesignal:OneSignal:[3.6.0,4.0.0)'
    compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.booking:rtlviewpager:1.0.1'
compile 'com.github.apg-mobile:android-round-textview:v0.0.3'
compile 'com.github.chrisbanes:PhotoView:1.3.0'

    compile 'com.google.code.gson:gson:2.8.0' //WC
    compile 'com.google.android.exoplayer:exoplayer:r2.4.3' //TV & Radio

     compile "com.android.support:cardview-v7:$supportlib_version"
    compile "com.android.support:appcompat-v7:$supportlib_version"
    compile "com.android.support:recyclerview-v7:$supportlib_version"
    compile "com.android.support:design:$supportlib_version"
    compile "com.android.support:support-v4:$supportlib_version"
    compile "com.android.support:support-core-utils:$supportlib_version"
    compile "com.android.support:support-media-compat:$supportlib_version"

    compile "com.google.android.gms:play-services-gcm:$gps_version"
    compile "com.google.android.gms:play-services-ads:$gps_version"
    compile "com.google.android.gms:play-services-maps:$gps_version"
    compile 'com.google.maps.android:android-maps-utils:0.5+'
    compile files('libs/YouTubeAndroidPlayerApi.jar')
    }

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

对于mw没什么用。我在很多论坛上尝试了很多解决方案

1 个答案:

答案 0 :(得分:0)

您需要更新到Android Studio 3.0版

还要确保在root gradle.build中添加了新的repo

repositories {
    maven {
        url 'https://maven.google.com'
    }
}

您也可以使用较新的gradle包装器

repositories {
        maven {
            google()
        }
    }

如果您在repo中使用过数据绑定,请确保已添加

android {
    ....
    dataBinding {
        enabled = true
    }
}

这是最好的方法。

在根级别gradle.build使用下面的

buildscript {
    repositories {
        mavenCentral()
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

task clean(type: Delete) {
    delete rootProject.buildDir
}

并在gradle-wrapper.properties文件中更改包装器版本,如下所示

distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip

同样在您的应用级别build.gradle中,请确保您使用的是26版本,如下所示

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.xxxx"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multidexenabled = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}