1

I hope you can help me, I'm trying to implement autovalue in my android project, but the code is not been generated.

I added in app/build.gradle:

provided 'com.google.auto.value:auto-value:1.5.3'
annotationProcessor 'com.google.auto.value:auto-value:1.5.3'

annotationProcessor 'com.ryanharter.auto.value:auto-value-gson:0.7.0'
compile 'com.ryanharter.auto.value:auto-value-gson-annotations:0.7.0'

In android studio 3.0 default settings in compiler > annotation processors I checked Enable annotation processing, and selected Obtain processors from project classpath.

I created AutoValueGsonFactory class like this:

import com.google.gson.TypeAdapterFactory;
import com.ryanharter.auto.value.gson.GsonTypeAdapterFactory;

@GsonTypeAdapterFactory
public abstract class AutoValueGsonFactory implements TypeAdapterFactory {

    // Static factory method to access the package
    // private generated implementation
    public static TypeAdapterFactory create() {
        return new AutoValueGson_AutoValueGsonFactory();
    }
}

Then I click on Build > Rebuild Project

But is not working, throw this error:

Error:(16, 20) error: cannot find symbol class AutoValueGson_AutoValueGsonFactory

What I'm doing wrong or what I'm missing?

Kevin Ramirez Zavalza
  • 1,629
  • 1
  • 22
  • 34

1 Answers1

2

Create one model class and then rebuild the project. The Error will be gone by now :)

Below is a sample model class created using ROBOPOJO plugin in android studio

import com.google.auto.value.AutoValue;
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.Gson;
import com.intellicar.finder.Data;

@AutoValue
public abstract class LoginData{

    @SerializedName("msg")
    public abstract String msg();

    @SerializedName("data")
    public abstract Data data();

    @SerializedName("err")
    public abstract Object err();

    @SerializedName("status")
    public abstract String status();

    public static TypeAdapter<LoginData> typeAdapter(Gson gson) {
        return new AutoValue_LoginData.GsonTypeAdapter(gson);
    }
}
Nihas Nizar
  • 619
  • 8
  • 15