Robertas Setkus
Robertas Setkus

Reputation: 3161

Android Gradle Plugin 3.0 Build Error

Experiencing issues migrating to Android gradle plugin 3.0.

build.gradle file on the root of project

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

Android Application Module 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.

enter image description here

But once retrolambda is added back again then the project compiles and builds successfully. Read through "Known Issues" section and didn't find a fix. I hope somebody experienced this and can help.

Upvotes: 10

Views: 2025

Answers (4)

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75778

Did you set

apply plugin: 'me.tatarka.retrolambda'

Add the me.tatarka:gradle-retrolambda plug-in as dependency to your build.gradle file.

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.

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

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. To use a different version of the build tools, specify it using buildToolsVersion in your module's build.gradle, as follows:

/**
   * 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.

android { 
    compileSdkVersion 27 
    buildToolsVersion "27.0.0" 

Then Clean-Rebuild-Restart-Run.

Read

Upvotes: 3

user1773603
user1773603

Reputation:

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:

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:

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

Upvotes: 5

Jigar Patel
Jigar Patel

Reputation: 1568

Make sure your BuildToolsVersion is up 26

new android studio 3.0 after required minimum buildToolsVersion 26.0.0 update this version in-app module gradle.

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.3"
}

If you see the buildtool not found error you need install this build tool.

Upvotes: 2

Mallikarjuna
Mallikarjuna

Reputation: 884

Make Sure these Lines In App(module) level gradle file

buildToolsVersion

defaultConfig for App Configuration

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
    }

}

Upvotes: 0

Related Questions