after migrating to Android 3.0 I've changed gradle configurations in my projects. In one of them I get errors while trying to do the build:
Execution failed for task ':app:compileDebugKotlin'.
e: C:\dev\myapp\app\src\main\kotlin\com\xxxxx\dialog\DeleteConfirmDialog.kt: (35, 46): Too many arguments for public constructor Builder(p0: Context!) defined in android.app.AlertDialog.Builder
e: C:\dev\myapp\app\src\main\kotlin\com\xxxxx\dialog\HumidityThresholdDialog.kt: (46, 74): Too many arguments for public open fun getString(p0: String!): String! defined in android.os.Bundle
e: C:\dev\myapp\app\src\main\kotlin\com\xxxxx\dialog\PermissionDialog.kt: (45, 50): Unresolved reference: ACTION_APcomICATION_DETAILS_SETTINGS
e: C:\dev\myapp\app\src\main\kotlin\com\xxxxx\dialog\PermissionDialog.kt: (53, 22): Unresolved reference: finishAffinity
e: C:\dev\myapp\app\src\main\kotlin\com\xxxxx\dialog\TemperatureThresholdDialog.kt: (74, 73): Unresolved reference: holo_red_dark
e: C:\dev\myapp\app\src\main\kotlin\com\xxxxx\dialog\TemperatureThresholdDialog.kt: (81, 88): Unresolved reference: holo_red_dark
e: C:\dev\myapp\app\src\main\kotlin\com\xxxxx\fragment\Thresholds.kt: (128, 41): Unresolved reference: fragmentManager
e: C:\dev\myapp\app\src\main\kotlin\com\xxxxx\fragment\Thresholds.kt: (153, 38): Unresolved reference: fragmentManager
...
What is interesting, when I navigate to error lines, eg:
val color = if (it) android.R.color.black else android.R.color.holo_red_dark //Unresolved reference: holo_red_dark
dialog.show(activity.fragmentManager, ThresholdDialog::class.java.simpleName) //Unresolved reference: fragmentManager
the compiler doesn't show an error and I can navigate to those classes.
Project:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://raw.github.com/vRallev/mvn-repo/master/' }
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1' //<--- when reverting back to 2.3.3, the project is built without problems
classpath 'io.fabric.tools:gradle:1.23.0'
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}
}
App:
buildscript {
ext.versions = [
kotlin : '1.1.60',
crashlytics: '1.16.0'
]
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
maven { url "https://plugins.gradle.org/m2/" }
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath "com.crashlytics.tools.gradle:crashlytics-gradle:$versions.crashlytics"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$versions.kotlin"
classpath "org.kordamp:markdown-gradle-plugin:1.1.0"
classpath 'io.fabric.tools:gradle:1.23.0'
}
}
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://jitpack.io' }
mavenLocal()
mavenCentral()
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'org.kordamp.markdown.convert'
apply from: 'signing.gradle'
def version = ["major": 3, "minor": 6, "patch": 1, "build": 0]
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.xxxxx"
minSdkVersion 19
targetSdkVersion 26
versionCode 10000000 * version["major"] + 100000 * version["minor"] + 1000 * version["patch"] + version["build"]
versionName "${version["major"]}.${version["minor"]}.${version["patch"]}"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7 //<- tried to changed to 1_8 with android studio 3, doesn't help
targetCompatibility JavaVersion.VERSION_1_7
}
signingConfigs {
release
}
buildTypes {
release {
// runProguard false
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
zipAlignEnabled true
signingConfig signingConfigs.release
}
debug {
ext.enableCrashlytics = false
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
main.assets.srcDirs += 'build/gen-html'
androidTest.java.srcDirs += 'src/androidTest/kotlin'
}
lintOptions {
checkReleaseBuilds false
disable 'InvalidPackage'
}
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
exclude 'META-INF/LICENSE.txt'
}
}
ext.versions += [
supportLib : "26.1.0",
logback : '1.1.1-2',
dagger : '1.2.5',
butterknife: '7.0.1'
]
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) //changed all 'compile' to 'implementation', doesn't help
compile 'com.xxxxx.lib:1.0.1-SNAPSHOT@aar'
compile "com.android.support:support-v4:$versions.supportLib"
compile "com.android.support:support-v13:$versions.supportLib"
compile "com.squareup.dagger:dagger:$versions.dagger"
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
compile 'com.google.guava:guava:20.0'
compile 'de.greenrobot:eventbus:2.2.1'
compile 'org.slf4j:slf4j-api:1.7.6'
compile "com.github.tony19:logback-android-core:$versions.logback"
compile "com.github.tony19:logback-android-classic:$versions.logback"
compile "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlin"
compile 'io.reactivex:rxjava:1.0.16'
compile 'io.reactivex:rxkotlin:0.40.1'
compile "com.jakewharton.rxbinding:rxbinding:0.4.0"
compile "com.jakewharton.rxbinding:rxbinding-kotlin:0.4.0"
compile "com.jakewharton:butterknife:$versions.butterknife"
compile 'com.jakewharton.threetenabp:threetenabp:1.0.3'
compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') { transitive = true }
compile 'com.github.PhilJay:MPAndroidChart:v2.0.7'
kapt "com.jakewharton:butterknife:$versions.butterknife"
kapt "com.squareup.dagger:dagger-compiler:$versions.dagger"
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.9.0'
testCompile 'org.assertj:assertj-core:3.8.0'
}
markdownToHtml {
sourceDir = file('src/main/markdown')
fencedCodeBlocks = true
hardwraps = true
autoLinks = true
}
project.afterEvaluate {
tasks.findByName('mergeDebugAssets')?.dependsOn tasks['markdownToHtml']
tasks.findByName('mergeReleaseAssets')?.dependsOn tasks['markdownToHtml']
}
What could be the issue?
I took a look at dependency tree and noticed that logback library was using an old android library which was pulled by gradle form repository and strangely used to compile the project.
After excluding it from gradle dependency the project started to build properly.