简体   繁体   English

Android Gradle Plugin 3.0构建错误

[英]Android Gradle Plugin 3.0 Build Error

Experiencing issues migrating to Android gradle plugin 3.0 . 遇到迁移到Android gradle插件3.0的问题

build.gradle file on the root of project 项目根目录下的build.gradle文件

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

Android Application Module build.gradle Android 应用程序模块build.gradle

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        mavenCentral()
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
        classpath testDependencies.spoon
    }
}

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

apply plugin: 'com.android.application'

apply plugin: 'io.fabric'

spoon {
    debug = true
    grantAllPermissions = true
    shard = true
}

android {
    compileSdkVersion 25

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

Trying to compile a project. 试图编译一个项目。 I am getting compilation errors. 我收到编译错误。

在此输入图像描述

But once retrolambda is added back again then the project compiles and builds successfully. 但是,一旦retrolambda再次被添加回来,那么该项目将成功编译和构建。 Read through "Known Issues" section and didn't find a fix. 阅读“已知问题”部分,但没有找到解决方法。 I hope somebody experienced this and can help. 我希望有人能够体验到这一点,并能提供帮助

If you do encounter a build error after updating the plugin, simply search this page for the error output or navigate to the related topic, and follow the instructions to resolve the issue. 如果在更新插件后确实遇到构建错误,只需在此页面中搜索错误输出或导航到相关主题,然后按照说明解决问题。

Solution: See at Known issues in refer page. 解决方案:请参阅参考页面中的已知问题。

For example, consider the following classpath dependencies included in the build.gradle file of the main project: 例如,请考虑主项目的build.gradle文件中包含的以下类路径依赖项:

buildscript {
    ...
    dependencies {
        classpath "com.android.tools.build:gradle:3.0.1"
        classpath "me.tatarka:gradle-retrolambda:3.7.0"
    }
}

Now consider the following build.gradle file for another project included in the composite build: 现在考虑复合构建中包含的另一个项目的以下build.gradle文件:

buildscript {
    dependencies {
        // Note that the order of plugins differs from that
        // of the main project's build.gradle file. This results
        // in a build error because Gradle registers this as a
        // different classloader.
        classpath "me.tatarka:gradle-retrolambda:3.7.0"
        classpath "com.android.tools.build:gradle:3.0.1"
    }
}

Did you set 你有没有订

apply plugin: 'me.tatarka.retrolambda'

Add the me.tatarka:gradle-retrolambda plug-in as dependency to your build.gradle file. me.tatarka:gradle-retrolambda插件添加为build.gradle文件的依赖build.gradle

buildscript {
   repositories {
      google()
      mavenCentral()
   }

   dependencies {
      classpath "com.android.tools.build:gradle:3.0.1"
      classpath 'me.tatarka:gradle-retrolambda:3.7.0'
   }
}

// Required because retrolambda is on maven central
repositories {
   mavenCentral()
}

Then Add the source and target compatibility to Java 8 and apply the new plug-in in your app/build.gradle file. 然后将源和目标兼容性添加到Java 8并在app/build.gradle文件中app/build.gradle新插件。

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda' // Add this 

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.0"

    defaultConfig {
        applicationId " "
        minSdkVersion //
        targetSdkVersion //
        versionCode //
        versionName //
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

FYI FYI

If you're using Android plugin for Gradle 3.0.0 or higher , your project automatically uses a default version of the build tools that the plugin specifies. 如果您使用Gradle 3.0.0 or higher版本的Android插件,您的项目将自动使用插件指定的默认版本的构建工具。 To use a different version of the build tools, specify it using buildToolsVersion in your module's build.gradle , as follows: 要使用不同版本的构建工具, buildToolsVersion模块的 build.gradle使用buildToolsVersion指定它,如下所示:

/**
   * buildToolsVersion specifies the version of the SDK build tools, command-line
   * utilities, and compiler that Gradle should use to build your app. You need to
   * download the build tools using the SDK Manager.
   *
   * If you're using Android plugin 3.0.0 or higher, this property is optional—
   * the plugin uses a recommended version of the build tools by default.
   */
    android {

        compileSdkVersion 26
        buildToolsVersion "26.0.2"
    }

You should upgrade your buildToolsVersion version. 您应该upgrade buildToolsVersion版本。

android { 
    compileSdkVersion 27 
    buildToolsVersion "27.0.0" 

Then Clean-Rebuild-Restart-Run . 然后Clean-Rebuild-Restart-Run

Read

Make sure your BuildToolsVersion is up 26 确保您的BuildToolsVersion已达26

new android studio 3.0 after required minimum buildToolsVersion 26.0.0 update this version in-app module gradle. 新的android studio 3.0经过必要的最小buildToolsVersion 26.0.0更新此版本的应用内模块gradle。

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.3"
}

If you see the buildtool not found error you need install this build tool. 如果您看到buildtool not found错误,则需要安装此构建工具。

Make Sure these Lines In App(module) level gradle file 确保这些行在App(模块)级别gradle文件中

buildToolsVersion buildToolsVersion

defaultConfig for App Configuration app Configuration的defaultConfig

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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