0

ISSUE SOLVED: posted in answer section below

Problem
After upgrading kotlin version to 1.3.61. I am not be able use withContext, Dispatchers IO, Main nothing is working. It's showing unresolved reference. Are there any bugs in new update of kotlin? or what? cause everything was working fine before.
I have opened my old projects same error unresolved reference with every Coroutine functions like i said withContext() etc. But suspend keyword is working with little coroutine icon/mark is showing as well, when i try to call another suspend function.

What i try?
Downgraded kotlin version to 1.3.50 or try to upgrade coroutine version 1.3.61 (which was silly) but nothing worked..
Continously trying to find but unfortunately couldn't find any fix.
Made a new project and tried to use in onCreate() method but still same.

EDIT:
Adding gradles:
build.gradle(Module:app)

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 28
    buildToolsVersion "29.0.0"
    defaultConfig {
        applicationId "com.example.daggerpractise"
        minSdkVersion 22
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    //Dagger 2
    implementation 'com.google.dagger:dagger:2.15'
    kapt 'com.google.dagger:dagger-compiler:2.15'
    // For android
    implementation 'com.google.dagger:dagger-android:2.15'
    implementation 'com.google.dagger:dagger-android-support:2.15'
    // if you use the support libraries
    kapt 'com.google.dagger:dagger-android-processor:2.15'

     // AndroidX support design (for nav drawer)
    // def material_version = "1.0.0-rc02"
    def material_version = "1.0.0"
    implementation "com.google.android.material:material:$material_version"

    implementation 'com.github.bumptech.glide:glide:4.10.0'
    kapt 'com.github.bumptech.glide:compiler:4.10.0'

    //MVVM and livedata
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'

    // Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.6.1'
    implementation 'com.squareup.retrofit2:converter-gson:2.6.1'

    // RxJava
    def rxjava_version = '2.1.1'
    implementation "io.reactivex.rxjava2:rxjava:$rxjava_version"
    // Rx-Retrofit Call Adapter
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
    // Retrofit call adapter

    // Kotlin Android Coroutines
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2'

}

build.gradle(Project: DaggerPractise)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.61'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // 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
}
USMAN osman
  • 952
  • 7
  • 13

2 Answers2

0

I was on kotlin 1.3.60 but upgraded to 1.3.61 after seeing this question in order to debug your issue.

After the upgrade, there was no error whatsoever.

Try invalidating android studio caches and restarting your android studio. This is likely an android studio cache issue.

Let me know if it worked for you.
Do this by clicking on the file tab at the upper left corner, then scroll down to invalidate caches/restart and click

Oluwasegun Wahaab
  • 2,663
  • 3
  • 16
  • 19
  • Thanks, did that twice but not working, still same. Even ``withContext()`` is not showing in suggestions but when i try ``Dispachers.IO``, IO shows as ``string`` whereas it should be coroutine dispatcher. BTW what's on your side? after upgrading, is it working fine? – USMAN osman Dec 11 '19 at 14:22
0

FIX:
When i found that my some of other things like some::class.java here java was unresolved error. Then i simply hop into the xml and try to add some widget just to make sure how xml is behaving, they were not adding means their properties were not showing like autocompeletion but fortunately i had a fix of that already. I thought it might be happening because of that which solved my all of issues.
Here is what you simply have to do, by the way it is something doing with android studio sub folders adding .bak extension to some folders anyways here it is:
https://stackoverflow.com/a/54007742/12397978

USMAN osman
  • 952
  • 7
  • 13