I'm having problems with the @StringDef support annotations. They work perfectly fine when the library they are in is part of the project (not an .aar file), but when I compile the library as .aar files and try to use them in another project, the annotations aren't enforced.
http://tools.android.com/tech-docs/support-annotations
Under the section "Using annotations in your own libraries" it says
If you annotate your own libraries with these annotations, and use Gradle to build an AAR artifact, at build time the Android Gradle plugin will extract annotation information and ship it inside your AAR file for use by clients of your library. You can take a look at the annotations.zip file inside the AAR where the information is recorded; this is using IntelliJ's external annotations XML format. This is necessary because .class files cannot contain enough information about annotations to handle the @IntDef information above; note that we need to record a reference to the constant itself, not its value. The Android Gradle plugin will run the extract annotations task as part of the build if (and only if) your project depends on the annotations support library. (Note that only the source-retention annotations are placed in the .aar file; the class level retentions are kept in classes.jar.)
I opened up the .aar file and inside there is the annotations.zip file, and if I extract that, there's an XML file that has all the correct annotations.
I'm using the @Retention(RetentionPolicy.SOURCE)
as it says I need to
The app that I'm trying to use these in as .aar files does have a dependency on the support library compile 'com.android.support:support-annotations:23.1.1
What am I missing to make these work?
Edit: I double checked that the project using these as .aar files also has the annotation processor turned on.
The issue was the interfaces were private.
For some reason a private interface works properly when a library project is compiled by it's host project as a sub module.
When the library project is used as an .aar file, the private interface no longer works.
As mentioned here, the information about constants used as @StringDef/@IntDef values will be lost once it is compiled into aar file. What remains is just values of the constants.
@IntDef annotations cannot be class retention because the thing they need to record (which constants are valid) cannot be expressed in the .class file -- the only data stored there for an annotation is the value of the constant, not some sort of pointer to the constant itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With