Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 859
Robertas Setkus Avatar asked Dec 20 '17 20:12

Robertas Setkus


2 Answers

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"
    }
}
like image 70
stefan Avatar answered Sep 20 '22 11:09

stefan


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

  • Recent Support Library Revisions
  • Migrating to Android 8.0
like image 36
IntelliJ Amiya Avatar answered Sep 19 '22 11:09

IntelliJ Amiya