17

I recently updated my kotlin and kotlin extensions plugin and while building I am getting the following error. I tried clean build or sync project with gradle but nothing works

e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
Error:Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details

The build.gradle is as follows

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

buildscript {
    ext.kotlin_version = '1.0.0-beta-1038'
    ext.anko_version = '0.7.2'
    ext.android_support_version = '23.0.1'
    ext.android_extensions_version = '1.0.0-beta-1038'

    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
    }
}


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.xxxxxxxxxx.app"
        minSdkVersion 18
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
        debug.java.srcDirs += 'build/generated/src/main/debug'
        release.java.srcDirs += 'build/generated/src/main/release'
    }
    dexOptions {
        preDexLibraries = false
        javaMaxHeapSize "4g"
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}

repositories {
    jcenter()
    mavenCentral()
    jcenter { url "https://jitpack.io" }
}

dependencies {
    provided fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'io.realm:realm-android:0.83.0'
    compile 'com.github.PhilJay:MPAndroidChart:v2.1.3'
    compile 'com.braintreepayments.api:braintree:1.+'
    compile('com.mikepenz:materialdrawer:4.4.1@aar') {
        transitive = true
    }
    compile 'com.mikepenz:google-material-typeface:1.2.0.1@aar'
    compile project(':temperature')
    compile project(':heart')
    compile project(':lungs')
    compile "com.android.support:cardview-v7:$android_support_version"
    compile 'com.github.wendykierp:JTransforms:3.1'
    compile 'fuel:fuel:0.57'
    compile "org.jetbrains.anko:anko-sdk15:$anko_version"
    compile "org.jetbrains.anko:anko-support-v4:$anko_version"
    compile 'org.apache.directory.studio:org.apache.commons.io:2.4'
    compile 'com.google.android.gms:play-services:8.1.0'
    compile "com.android.support:recyclerview-v7:$android_support_version"
    compile "com.android.support:appcompat-v7:$android_support_version"
    compile "com.android.support:support-v4:$android_support_version"
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

can someone point out what is the issue with this?

Thanks

User
  • 1,186
  • 4
  • 22
  • 36
  • I am having the same issue when adding Google Play Services. – Samuel Barbosa Nov 01 '15 at 02:50
  • 2
    I resolved this issue by updating all my other modules in the project with the current kotlin version and also I updated my dependencies version to the latest available. – User Nov 07 '15 at 06:40

4 Answers4

14

I solved this problem by building the project in terminal then run app in intellij(or android studio).

gradle clean build -> run app in ide

Myeonseok Baek
  • 318
  • 1
  • 4
  • 9
  • After checking and rechecking everything possible, I drove crazy and this comment was the correct answer. Have no idea why, but worked. Thanks ! – Samuelens May 15 '17 at 11:21
  • While running unit tests how many time to perform clean build? – takharsh Jan 17 '20 at 11:28
4

For me, the solution was to open the Gradle Console window in Android Studio and run the build with a StackTrace.

Then, reading through that, I realised that the new of doing some things in Kotlin required my code to change, but a normal Gradle build didn't catch those problems.

It was things like views being cast to TextView or whatever the case might be, that was not relevant anymore, and had to be changed to the findVieById format. e.g.:

val textView = snackbarView.findViewById(R.id.snackbar_text) as TextView

had to be changed to

val textView = snackbarView.findViewById<TextView>(R.id.snackbar_text) 
marienke
  • 2,465
  • 4
  • 34
  • 66
  • I think your issue was with the buildToolsVersion/appcompat version. not the kotlin plugin. because `findViewById` is part of android O. – crgarridos Sep 22 '17 at 14:19
  • @crgarridos, even though that is probably true, it helped me find the real things that bothered the Gradle build. I was getting the exact same messages as the question posted. – marienke Sep 26 '17 at 08:16
0

In the case of a project I was recently working on, I was getting the same kind of error, which was caused by a call to a static method that no longer existed.

MessageService.java

public class MessageService extends FirebaseMessagingService {

    /*
    This method was commented out

    private static String GetReviewTopic(String userId) 
    {
        return "/topics/"+userId+"/review";
    }
    */
}

AppActivity.java

@Override
public void onCreate() {

    ...

    /* 
    No complication error was caused despite the
    method not being defined. 
    */                        
    MessageService.GetReviewTopic(currentUser);

    ...
}

Unfortunately Android Studio wasn't reporting a "syntax error" for the missing static method, nor were there any meaningful complication errors that helped me track the issue down.

Hope this answer is able to save someone a few hours of troubleshooting!

Dacre Denny
  • 29,664
  • 5
  • 45
  • 65
0

What worked for me was: I updated the Kotlin version and the gradle dependency in the project/build.gradle to below:

buildscript {
    ext.kotlin_version = '1.7.0'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.15'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.7'
    }
}

And the distributionURL in the project/gradle/gradle-wrapper.properties to:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip

Lastly, I had to delete the duplicate files that were created in my project/android/app/src/main/kotlin created because my Flutter project was stored in my iCloud directory.

Dre Day
  • 25
  • 8