9

I just upgraded Android Studio to the latest stable version (Arctic Fox 2020.3.1) on Mac, and now my project doesn't build. I get a "Kotlin not configured" in the IDE top bar, and in the build output I get this error:

Could not find org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.5.21.
Required by:
    project :app

I tried to add this dependency to the app module Gradle file, but the error remains:

implementation "org.jetbrains.kotlin:kotlin-android-extensions-runtime:$kotlin_version"

For your reference, here is my Project Gradle file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext {
        kotlin_version = "1.5.21"
        version_navigation = "2.3.5"
        version_lifecycle_extensions = "2.2.0"
        version_lifecycle = "2.3.1"
        version_room = "2.4.0-alpha04"
        //version_room = "2.2.6"
        version_coroutine = "1.5.0"
        version_retrofit = "2.9.0"
        version_moshi = "1.9.3"
        version_retrofit_coroutines_adapter = "0.9.2"
        version_glide = "4.12.0"
    }
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
        classpath 'com.android.support:multidex:1.0.3'
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$version_navigation"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

And here is my Module Gradle file:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
    id "org.jetbrains.kotlin.kapt"
    id 'androidx.navigation.safeargs'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.virtualsheetmusic.vsheetmusic"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 20
        versionName "2.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        multiDexEnabled true

        vectorDrawables.useSupportLibrary = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }

    buildFeatures {

        //dataBinding includes viewBidning below https://stackoverflow.com/questions/58040778/android-difference-between-databinding-and-viewbinding
        dataBinding true

        // for view binding only:
        // viewBinding true
    }
}

dependencies {

    //implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    //implementation "org.jetbrains.kotlin:kotlin-android-extensions-runtime:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation "androidx.fragment:fragment-ktx:1.3.6"
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'

    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.jakewharton.timber:timber:4.7.1'

    //Lifecycle and LiveData
    implementation "androidx.lifecycle:lifecycle-extensions:$version_lifecycle_extensions"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$version_lifecycle"

    //Room
    implementation "androidx.room:room-runtime:$version_room"
    kapt "androidx.room:room-compiler:$version_room"

    // Kotlin Extensions and Coroutines support for Room
    implementation "androidx.room:room-ktx:$version_room"


    // Coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version_coroutine"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version_coroutine"

    // Testing
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    //For Internet connectiona and JSON stuff...

    // Moshi
    implementation "com.squareup.moshi:moshi:$version_moshi"
    implementation "com.squareup.moshi:moshi-kotlin:$version_moshi"

    // Retrofit
    implementation "com.squareup.retrofit2:retrofit:$version_retrofit"
    //implementation "com.squareup.retrofit2:converter-scalars:$version_retrofit"

    // Retrofit with Moshi Converter
    implementation "com.squareup.retrofit2:converter-moshi:$version_retrofit"
    implementation "com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:$version_retrofit_coroutines_adapter"

    //Glide
    implementation "com.github.bumptech.glide:glide:$version_glide"
    annotationProcessor "com.github.bumptech.glide:compiler:$version_glide"

    //Recyclerview swipe-refresh...
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

    //For PDF and download management from here: https://blog.mindorks.com/how-to-open-a-pdf-file-in-android-programmatically
    //https://github.com/barteksc/AndroidPdfViewer
    //implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
    implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
    //implementation 'com.mindorks.android:prdownloader:0.6.0'

    //This below to handle double clicks...
    //implementation 'com.gitlab.developerdeveloperdeveloper:androidutilslibrary:1.0.0'

}

I have already tried this:

  1. Build: Clean > Build
  2. Invalidate Caches / Restart

Any help is appreciated thanks!

UPDATE:

I solved this problem by adding back the jcenter() repository in the Project Gradle file which I removed because Android Studio marked is as "deprecated" (barred).

Now I get this other error, and I have no idea how to solve it:

Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
   > java.lang.reflect.InvocationTargetException (no error message)

Any thoughts? Thanks again.

Fabrizio Ferrari
  • 869
  • 2
  • 12
  • 25
  • 2
    Ok, I solved the problem by re-instantiating the center() repository in the Project Gradle file. I removed it because Android Studio marked it as deprecated (and barred), but it looks like it is still working. But how to definitively and safely remove it now that it is deprecated then? – Fabrizio Ferrari Jul 28 '21 at 21:40
  • 1
    There’s not a definitive way to successfully remove Jcenter. They’re shutting down the servers and it’s up to the authors of whatever plugins you’re using to migrate to other repos. If they don’t, you’re out of luck. – Tenfour04 Jul 28 '21 at 22:13
  • Ouch! Too bad! Fact is, now I get another error... here it is: "Execution failed for task ':app:kaptDebugKotlin'. > A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction > java.lang.reflect.InvocationTargetException (no error message)" – Fabrizio Ferrari Jul 28 '21 at 22:43
  • FWIW I'm on Arctic Fox 2020.3.1 and have already removed jcenter, but I'm using Kotlin version '1.5.10' – Daniel Nugent Jul 29 '21 at 00:05
  • Thank you for letting me know about that, but how do you define Kotlin's version? I have 203-1.5.21 defined and I can't seem to find a way to change it. – Fabrizio Ferrari Jul 29 '21 at 00:45
  • Oh, `kotlin-android-extenseions` is deprecated. You'll need to replace synthetics with view binding. https://stackoverflow.com/questions/65179275/the-kotlin-android-extensions-gradle-plugin-is-deprecated – Daniel Nugent Jul 29 '21 at 00:51
  • Ok, I can do that, but is that the cause of the error I am getting now? "Execution failed for task ':app:kaptDebugKotlin'."? – Fabrizio Ferrari Jul 29 '21 at 05:12
  • 1
    Ok, problem solved as explained here: https://stackoverflow.com/questions/68580677/updated-to-android-studio-arctic-fox-and-now-i-am-stuck-with-execution-failed-f/68583058#68583058 – Fabrizio Ferrari Jul 29 '21 at 21:38

2 Answers2

10

I did the same and got the same result, i solved it by Fil-> Sync project with gradle files

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/29794255) – Stefano Sansone Sep 10 '21 at 20:05
  • This post answer to the question by proposing a way to fix it (way that work for him) So for me it's fine – Elikill58 Sep 10 '21 at 21:33
0

Alternatively, You can use JDK version < 16. I have changed my JDK version from 16 to 15 in Preferences>Build, Execution, Deployment> Build Tools > Gradle and that solved my problem.

  • Thank you Kyaw. I'll do that in case I have issues with the solution I explained above. This should be a temporary issue anyway, right? I mean... it is my understanding that it'll be fixed in future versions. Am I right? – Fabrizio Ferrari Aug 18 '21 at 13:31