无法找到方法 'com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List;'

Unable to find method 'com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List;'

build.gradle

buildscript {
    ext.kotlin_version = '1.1.51'
    repositories {
        jcenter()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'me.tatarka:gradle-retrolambda:3.6.1'
        classpath 'com.google.gms:google-services:3.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

app/build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.7.0'
    }
}


      android{
            compileSdkVersion = 26  
            buildToolsVersion = "26.0.2"
    defaultConfig {
            minSdkVersion = 16
            targetSdkVersion = 26

        }
    ...
    applicationVariants.all { variant ->

        variant.outputs.all { output ->
            outputFileName = "newApkName.apk"
        }
    }
}

如何解决问题:

Unable to find method 'com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List;'.

Possible causes for this unexpected error include: Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network) The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart) Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project. In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

似乎问题不在 app/build.gradle 中,而是在 butterknife-gradle-plugin

通过删除 butterknife-gradle-plugin

解决

我在 gradle 同步时遇到了同样的错误,特别是与 butterknife 有关,我的解决方案已通过

解决

https://github.com/JakeWharton/butterknife/issues/963#issuecomment-339545297

tldr 在您的项目构建文件中...

buildscript{
 repositories {
   //other repos will likely exist here like jcenter and mavenCentral

   //add this closure
   maven {
    url "https://oss.sonatype.org/content/repositories/snapshots"
   }
  }
   dependencies {
    classpath 'com.jakewharton:butterknife-gradle-plugin:8.7.0'
    classpath 'com.android.tools.build:gradle:3.0.0'
    //change your version to 9.0.0-SNAPSHOT
     classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT'
    //.. other project level dependencies 
   }
 }
}

还要确保您的所有项目都包含

allproject{
  repositories{
    maven {
      //this
      url "https://oss.sonatype.org/content/repositories/snapshots"
    }
   }
 }

然后与 none butterknife 相关的问题在你的应用程序构建文件中将我的 buildToolsVersions 提升到 "26.0.2"

2018 年 4 月 19 日更新 自此与 butterknife 分道扬镳,因为它造成的问题比我使用过的任何其他第 3 方都多。此外,有了完整的 Kotlin 支持,就不需要 butterknife

根据 ElliotM 的回答:

  • 科特林 1.2.10
  • Gradle 3.0.1
  • 构建工具版本 27.0.3
  • 应用插件:'com.android.library'
  • 应用插件:'kotlin-android-extensions'
  • 应用插件:'kotlin-android'
  • 应用插件:'com.jakewharton.butterknife'

在我的图书馆项目中,这条评论帮助了我(R2 导入): https://github.com/JakeWharton/butterknife/issues/963#issuecomment-342547601

项目的build.gradle:

buildscript {
    repositories {
        maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT'
    }
}

repositories {
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}

模块的 build.gradle:

apply plugin: 'com.jakewharton.butterknife'

...

dependencies {
    compile 'com.jakewharton:butterknife:9.0.0-SNAPSHOT'
    kapt 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'
}

这样你就可以使用

apply plugin: 'com.jakewharton.butterknife'

我的解决方案是升级我的项目gradle

来自 : com.android.tools.build:gradle:3.1.4

至:com.android.tools.build:gradle:3.5.3