Pregunta

I'm currently trying to reduce my method count for an Android App so as to get it compiling again. One of the areas I'd like to improve upon is all the thrift generated files that are being used. It's insane how overly bloated simple thrift structs become.

For example this following thrift struct:

struct AccessoryLocalization {
    1: required string displayName;
    2: required string displaySummary;
}

Turns into a 475 lined java class!!! That seems insane to me, and I'm not totally understanding why it's generating so much. I am wondering if anyone knew of any way to get thrift to not be so verbose in their code generation.

I'm using Thrift 0.9.0 and using the java:android_legacy flag when running the thrift commands. I'm only concerned about supporting Gingerbread and up.

¿Fue útil?

Solución

So this is definitely an old question, but this week I released an Android-specific Thrift compiler and runtime that addresses these exact concerns:

https://github.com/Microsoft/thrifty

It generates code that

  1. uses as few methods as possible - no getters/setters/isSetters/setIsSetters
  2. is friendlier to Proguard (no storing pseudo-reflection TFields in static maps)
  3. offers a few Android-specific options like @Nullable/@NonNull annotations

It took our app from 20K methods of Thrift classes to 5K. Hopefully it can help you (or others who find this question).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top