11

迁移到Android gradle plugin 3.0时遇到问题。

项目根目录下的build.gradle 文件

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

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
    }
}

试图编译一个项目。我收到编译错误。

在此处输入图像描述

但是一旦再次添加retrolambda,项目就会成功编译和构建。通读“已知问题”部分并没有找到解决方法。我希望有人经历过这个并且可以提供帮助。

4

4 回答 4

5

如果您在更新插件后确实遇到构建错误,只需在此页面搜索错误输出或导航到相关主题,然后按照说明解决问题。

解决方案:请参阅参考页面中的已知问题。

例如,考虑包含在主项目的 build.gradle 文件中的以下类路径依赖项:

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

现在考虑组合构建中包含的另一个项目的以下 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"
    }
}
于 2017-12-28T14:02:19.657 回答
3

你设置了吗

apply plugin: 'me.tatarka.retrolambda'

me.tatarka:gradle-retrolambda插件作为依赖项添加到您的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()
}

然后添加源和目标兼容性Java 8并将新插件应用到您的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
    }
}

供参考

如果您使用 Android 插件Gradle 3.0.0 or higher,您的项目会自动使用插件指定的构建工具的默认版本。要使用不同版本的构建工具,buildToolsVersion请在您的模块 build.gradle中指定它,如下所示:

/**
   * 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"
    }

你应该upgrade你的buildToolsVersion版本。

android { 
    compileSdkVersion 27 
    buildToolsVersion "27.0.0" 

然后Clean-Rebuild-Restart-Run

于 2017-12-28T09:40:11.480 回答
2

确保您的 BuildToolsVersion 为 26

需要最低 buildToolsVersion 26.0.0 后新的 android studio 3.0 更新此版本应用内模块 gradle。

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.3"
}

如果您看到 buildtool not found 错误,您需要安装此构建工具。

于 2017-12-28T05:46:13.103 回答
1

确保这些行在 App(module) 级别的 gradle 文件中

buildTools版本

应用配置的 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
    }

}
于 2017-12-28T05:23:28.750 回答