Strange build errors after upgrading to kotlin plugin 3.0.0+

Hi,
after migrating to Android Studio 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 {
        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 {
        jcenter()
        mavenCentral()
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
        maven { url 'https://maven.google.com' }
    }
}

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 {

implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'com.xxxxx.lib:1.0.1-SNAPSHOT@aar'

implementation "com.android.support:support-v4:$versions.supportLib"
implementation "com.android.support:support-v13:$versions.supportLib"
implementation "com.squareup.dagger:dagger:$versions.dagger"
implementation 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
implementation 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
implementation 'com.google.guava:guava:20.0'
implementation 'de.greenrobot:eventbus:2.2.1'
implementation 'org.slf4j:slf4j-api:1.7.6'
implementation "com.github.tony19:logback-android-core:$versions.logback"
implementation "com.github.tony19:logback-android-classic:$versions.logback"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlin"
implementation 'io.reactivex:rxjava:1.0.16'
implementation 'io.reactivex:rxkotlin:0.40.1'
implementation "com.jakewharton.rxbinding:rxbinding:0.4.0"
implementation "com.jakewharton.rxbinding:rxbinding-kotlin:0.4.0"
implementation "com.jakewharton:butterknife:$versions.butterknife"
implementation 'com.jakewharton.threetenabp:threetenabp:1.0.3'

implementation('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') { transitive = true }
implementation 'com.github.PhilJay:MPAndroidChart:v2.0.7'

kapt "com.jakewharton:butterknife:$versions.butterknife"
kapt "com.squareup.dagger:dagger-compiler:$versions.dagger"

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.9.0'
testImplementation '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']
}

I’ve tried cleaning project and other common solutions but without any success.
What could be the issue?

The most likely issue that I can see is that you have a library that no longer exposes its own dependencies to your app (depending on the library). Newer gradle versions (4+) separate this, and the android plugin 3 also uses it.

Thank you for the response.
I’m not sure how to address that.
The compilation errors point to android package (android.app, android.os).

For example ‘Too many arguments for public constructor Builder(p0: Context!) defined in android.app.AlertDialog.Builder’ may indicate that the compiler resolves the class but the signature doesn’t match.
On the other hand we got couple of ‘Unresolved reference’ issues.

To be honest I’m completely stuck and out of ideas what to try to find the issue.

I took a look at dependency tree and noticed that logback library was using old android library which was pulled by gradle form repository.

+--- com.github.tony19:logback-android-classic:1.1.1-2
|    +--- com.github.tony19:apktool-lib:1.4.4-3
|    |    \--- com.google.android:android:2.1_r1

After excluding it from gradle dependency the project started to build properly.

implementation('com.github.tony19:logback-android-classic:1.1.1-6') {
	exclude group: 'com.google.android', module: 'android'
}

Thank’s for libraries-related suggestions :slight_smile: