简体   繁体   中英

Unresolved reference: ActivityCompat in Android Kotlin

I am implementing OCR results in android using kotlin language by this tutorial

I am unable to solve this ActivityCompat error

import android.support.v4.app.ActivityCompat

My Gradle file:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.example.ocrofflinesample"
        minSdkVersion 21
        targetSdkVersion 29
        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.0.2'
   // implementation 'androidx.support:appcompat-v7:'

    implementation 'androidx.core:core-ktx:1.0.1'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.gms:play-services-vision:15.0.1'
    implementation "org.jetbrains.anko:anko:0.10.4"

    //  Logger
    implementation 'com.orhanobut:logger:2.1.1'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

How to resolve this `ActivityCompat error`?

You have to use Androidx dependency. Change the android.support.v4.app.ActivityCompat to androidx.core.app.ActivityCompat

Check this out for pre-Androidx to Androidx dependencies mapping.

You might have either used AndroidX while creating project, or you have used AndroidX dependencies in non - androidX artifact.

Either you need to migrate it to androidX as suggested above.

Also, if you have used app:layout_scrollFlags in layouts, you might wanna check out the scroll constants after refactor because recently when I refactored, I didn't get any build error but when the activity with scrollFlags loaded, it crashed and upon finding out, it was a refactor issue due to that it was unable to change constant names as per AndroidX.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM