Support Annotation does not exist after upgrading to Android Studio 3.0
H

5

21

After I upgrade my project to AndroidStudio 3.0-beta1, my androidTest files stopped compiling.

A lot of packages are not found, some of them are:

error: package android.support.annotation does not exist
error: cannot find symbol class StringRes
error: cannot access AppCompatActivity
class file for android.support.v7.app.AppCompatActivity not found

I already added

androidTestCompile "com.android.support:support-annotations:25.3.1"

into build.gradle

But even with this, I have the errors of package not found. I tried running the tests from inside Android Studio and from terminal with ./gradlew connectedCheck

Heuser answered 11/8, 2017 at 2:9 Comment(3)
Besides adding the dependency explicitely for androidTest also need to exclude the support-annotations for those dependencies which introduce it as a transitive dependency. You can use the GradleView plugin to find out which of your dependencies depends on support-annotations. Otherwise one of the libraries might raise your support-annotations version.Croupier
Updating butterknife to latest version solved my problemPorous
In my case after I migrated to androidX I got this error.Lidstone
S
4

I had the same problem. The issue is not that you upgraded AndroidStudio but that your target version and compile version are below 26 after updating the build tools in your SDK.

So changing

android {
    compileSdkVersion 25

    defaultConfig {
        applicationId "bla.bla"
        minSdkVersion 21
        targetSdkVersion 25
    }
}

to

android {
    compileSdkVersion 26

    defaultConfig {
        applicationId "bla.bla"
        minSdkVersion 21
        targetSdkVersion 26
    }
}

solves the issue.

Statant answered 28/8, 2017 at 11:38 Comment(4)
both target version and compile version are at 26 and it still doesn't work.Roughspoken
It is about the annotation support packageGlynisglynn
@Godwin try implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'Idel
This is not the root cause.Cession
B
10

Just add this to your dependencies

implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation "com.android.support:support-annotations:28.0.0"
annotationProcessor 'com.android.support:support-annotations:28.0.0'
Baccy answered 10/9, 2019 at 2:58 Comment(1)
Thanks Fattie! I really appreciateBaccy
S
4

I had the same problem. The issue is not that you upgraded AndroidStudio but that your target version and compile version are below 26 after updating the build tools in your SDK.

So changing

android {
    compileSdkVersion 25

    defaultConfig {
        applicationId "bla.bla"
        minSdkVersion 21
        targetSdkVersion 25
    }
}

to

android {
    compileSdkVersion 26

    defaultConfig {
        applicationId "bla.bla"
        minSdkVersion 21
        targetSdkVersion 26
    }
}

solves the issue.

Statant answered 28/8, 2017 at 11:38 Comment(4)
both target version and compile version are at 26 and it still doesn't work.Roughspoken
It is about the annotation support packageGlynisglynn
@Godwin try implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'Idel
This is not the root cause.Cession
L
2

In my case it happened after migrating to androidX . The decision merely was :

go to the *.java file(s) pointed and comment strings with packages

 //import android.???

and re-import androidX-ed ones.

Build the project again and you are done.

Lidstone answered 20/6, 2019 at 5:22 Comment(0)
M
2

Try this:

import androidx.annotation.StringRes
Maize answered 12/1, 2020 at 0:36 Comment(0)
P
0

I had got similar errors and corrected it by adding.

LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4
inside your Android.mk folder.

Note: This is for change in binary directly where you have to run .mk file separately. If using Android Studio, check Writing Android.mk file in Studio.
I read the previous answer and wanted to provide a different approach to correct it although its harder this way.

Provided answered 24/4, 2019 at 10:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.