I am updating my project's Gradle plugin from 2.1.2 to 3.1.0 but the gradle starts throwing error while build :
Cannot create variant 'android-lint' after configuration ':app:debugRuntimeElements' has been resolved
project level gradle :
// Top-level build file
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'org.ajoberstar:gradle-git:0.6.3'
//noinspection GradleDynamicVersion
classpath 'io.fabric.tools:gradle:1.+'
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
classpath 'com.google.gms:google-services:3.0.0'
}
}
// Used to disable preDex, will speed up clean build but slow down incremental builds.
project.ext.preDexLibs = !project.hasProperty('disablePreDex')
subprojects {
project.plugins.whenPluginAdded { plugin ->
if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
} else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
}
}
}
allprojects {
repositories {
jcenter()
}
}
library level gradle :
apply plugin: 'com.android.library'
setVersion '1.2'
repositories {
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
configurations {
classpaths
}
def sharedManifest = manifest {
attributes('Specification-Title': 'My App',
'Specification-Version': '2.1',
'Specification-Vendor': 'App Vendor',
'Implementation-Title': 'App',
'Implementation-Version': '2.1',
'Implementation-Vendor': 'App Vendor')
}
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
minSdkVersion 15
targetSdkVersion 27
consumerProguardFile file("proguard-project.txt")
}
buildTypes {
debug {
testCoverageEnabled true
}
}
// work-around for duplicate files during packaging of APK
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation project(':exclude-doclet')
implementation 'com.android.support:support-annotations:27.0.2'
implementation 'com.android.support:support-v4:27.0.2'
implementation 'commons-io:commons-io:2.4'
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
implementation 'com.google.code.gson:gson:2.4'
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'io.reactivex:rxjava:1.1.7'
classpaths files(new File(System.getenv("ANDROID_HOME") + "/platforms/android-${Integer.parseInt(rootProject.ANDROID_BUILD_SDK_VERSION)}/android.jar"),
new File(System.getenv("ANDROID_HOME") + "/extras/android/support/v4/android-support-v4.jar"))
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:1.10.19'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'org.mockito:mockito-core:1.10.19'
}
android.libraryVariants.all { variant ->
String name = variant.buildType.name
task("generate${name.capitalize()}Javadoc", type: Javadoc) {
dependsOn variant.javaCompiler
description "Generates Javadoc for $project.name."
title "App $project.version"
source = variant.javaCompiler.source
classpath += project.files(variant.javaCompiler.classpath.files, android.getBootClasspath())
List<File> pathList = new ArrayList<File>()
pathList.add(new File(project(':exclude-doclet').libsDir,
"ExcludeDoclet-${project(':exclude-doclet').version}.jar"))
options {
doclet = "ExcludeDoclet"
docletpath = pathList
encoding = "UTF-8"
classpath = configurations.classpaths.files.asType(List)
linksOffline "http://developer.android.com/reference", "${android.sdkDirectory}/docs/reference"
links "http://docs.oracle.com/javase/7/docs/api/",
"http://square.github.io/retrofit/2.x/retrofit/",
"http://square.github.io/okhttp/2.x/okhttp/",
"http://reactivex.io/RxJava/javadoc/"
memberLevel = JavadocMemberLevel.PUBLIC
header = "AppKit"
}
exclude '**/BuildConfig.java'
exclude '**/R.java'
failOnError true
doLast {
copy {
from 'src/javadoc/assets/'
into destinationDir.path + '/assets/'
}
}
}
task("assemble${name.capitalize()}JavadocJar", type: Jar) {
dependsOn "generate${name.capitalize()}Javadoc"
description "Assembles Jar contaning Javadoc for $project.name."
from project.tasks.getByName("generate${name.capitalize()}Javadoc").destinationDir
classifier = 'javadoc'
manifest {
from sharedManifest
}
}
task("assemble${name.capitalize()}Jar", type: Jar) {
dependsOn variant.javaCompiler
description "Assembles Jar contaning $project.name."
from variant.javaCompiler.destinationDir
manifest {
from sharedManifest
}
}
artifacts {
archives project.tasks.getByName("assemble${name.capitalize()}Jar")
archives project.tasks.getByName("assemble${name.capitalize()}JavadocJar")
}
}
I am stuck with this issue and don't find any solution. Can anyone help me out.
I had the same issue with another library as you have. I could resolve that with replacing this line:
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
with:
doFirst { classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar) },
"This is due to new Gradle plugin when AndroidStudio gets updated that goes in conflict with JavaDoc plugin", If you have Javadoc task you must be able to find the same line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With