Add annotation processor for generating keep rules for types mentioned only inside generics
See original GitHub issueOtherwise they will be removed by R8 since it cannot determine whether we are doing reflection on them.
Old issue below:
Using com.squareup.retrofit2:retrofit:2.9.0
After upgrading gradle plugin from
com.android.tools.build:gradle:4.1.3
to
com.android.tools.build:gradle:4.2.2
I’m getting following error when running with minifyEnabled true:
java.lang.IllegalArgumentException: Method return type must not include a type variable or wildcard
Here’s how looks the method, which generates the error:
@FormUrlEncoded
@POST("view_ad") //NON-NLS
Call<GenericDataResponse<EmptyData>> viewAd(
@Field("session_id") String sessionId, //NON-NLS
@Field("id") int id //NON-NLS
);
public class EmptyData {
public EmptyData(){}
}
public class GenericDataResponse<T> {
@SerializedName("result") //NON-NLS
public String result;
@SerializedName("data") //NON-NLS
public T data;
@SerializedName("mess") //NON-NLS
public String[] messages;
}
In order to fix this I have to either:
- downgrade to the previous gradle plugin version
- add proguard rule: -keep class com.example.app.EmptyData
- disable proguard/r8
I’ve read the docs about gradle 4.2 changes and nothing seems to be related to proguard directly. Can someone explain what’s going on?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:21 (4 by maintainers)
Top Results From Across the Web
Configure annotation processors | IntelliJ IDEA Documentation
You can create a new profile, group several modules under it and configure an annotation processing just for the specified group of modules....
Read more >Annotation Processing 101 - Hannes Dorfmann
Annotation processing is a tool build in javac for scanning and processing annotations at compile time. You can register your own annotation ......
Read more >Annotation Processor appears to break Java generics
You say that the user will need the concrete (generic) types, but they actually won't need them if they only interact with the...
Read more >An Introduction to Annotations and Annotation Processing in ...
The java.lang package provides some core annotations and also gives us the capability to create our custom annotations that can be processed ...
Read more >javac - Java programming language compiler
The directory must already exist; javac will not create it. ... -proc:only means that only annotation processing is done, without any subsequent compilation ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

On a class, the signature I’ve got is similar to this:
@GET("endpoint") fun getData(): Single<List<SomeClass>>And adding the
@Keepannotation toSomeClasshelpedWhen running R8 in full mode all generic types are removed unless they are explicitly kept. Retrofit automatically keeps the generic part for users of
Call, but if you are using Rx or Kotlin or some other library as your adapter it will not work (and it’s wasteful to keep the generic on all usages of those types). The only way is to explicitly keep the body types, hence the annotation processor.