10

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?

Community
  • 1
  • 1
aga
  • 27,954
  • 13
  • 86
  • 121

4 Answers4

7

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.

gladed
  • 1,705
  • 1
  • 17
  • 25
1

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'
Wasi Sadman
  • 1,382
  • 1
  • 15
  • 27
0

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.

Samuel Peter
  • 4,136
  • 2
  • 34
  • 42
  • I built the project before asking a question. Projects build and runs fine, but Android Studio editor does not resolve AutoValue_Something classes and marks them as errors. – aga Apr 08 '16 at 12:58
  • 2
    hum... do you have `apply plugin: 'com.neenbedankt.android-apt'` in your build.gradle, and `apt "com.google.auto.value:auto-value:"` in your dependencies ? – Samuel Peter Apr 08 '16 at 13:12
  • Yes, As a matter of fact, apt generates two classes in build/generated/source/apt folder, called AutoValue_DrawableContent.java and $AutoValue_DrawableContent.java. But for some reason that's not enough. – aga Apr 08 '16 at 13:15
  • Are you sure that you are using the android-apt plugin as opposed to the gradle apt plugin which is referenced in AutoValue docs ? The android-apt plugin is installed by adding `classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'` to the buildscript dependencies in the project's build.gradle and `apply plugin: 'com.neenbedankt.android-apt'` to the module build.gradle. If you are using `net.ltgt.apt` instead, Android Studio won't pick up the generated files. – Samuel Peter Apr 08 '16 at 13:42
  • By the way, since you seem to want to implement Parcelable as well, you can use AutoParcel instead of AutoValue : https://github.com/frankiesardo/auto-parcel – Samuel Peter Apr 08 '16 at 13:46
0
  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.
EastOcean
  • 1,222
  • 11
  • 10