aga
aga

Reputation: 29416

Android Studio can not resolve AutoValue class

I started to use AutoValue today in one of my projects and what bothers me is that Android Studio can not resolve the generated class name (AutoValue_DrawableContent) and marks it with the red color:

enter image description here

How I can suppress this warning?

Upvotes: 10

Views: 5304

Answers (4)

Wasi Sadman
Wasi Sadman

Reputation: 1482

you can just comment out each dependencies and sync one by one... it might get things fixed...

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

Upvotes: 1

gladed
gladed

Reputation: 1743

Add the "idea" plugin to your build.gradle, for example:

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'net.ltgt.apt'

With this plugin, Android Studio can find the generated source files.

Upvotes: 7

EastOcean
EastOcean

Reputation: 1252

  1. Generate implementation class(es). AutoValue lib will do that.
  2. Add these dynamically class(es) directory into source path. android-apt plugin will do this. After doing this, ide will know AutoValue_* and not to show errors.

Upvotes: 0

Samuel Peter
Samuel Peter

Reputation: 4166

Now that you have annotated your class, you need to build your project. This will generate the missing class, and Android Studio will be able to find it afterwards.

The build will not fail even though the editor is currently not recognizing the class name, because code generation will happen before the class is compiled.

Upvotes: 0

Related Questions