Annotation processing with kapt Android Studio -


i'm trying use kapt using annotation processor. ran few problems.

annotation processor jar connected way:

    kapt files('libs/processor.jar')     provided files('libs/processor.jar') 

1) i'm using javapoet code generation. , saving class way

    javafile javafile = javafile.builder(package, typespec).build();     javafile.writeto(processingenv.getfiler()); 

but saves build\generated\source\kapt\release, , never debug folder regardless of build variant.

enter image description here

2) second problem generated file doesn't refresh, until press build->rebuild

the kotlin-kapt plugin automatically select correct output directory based on built library/application variant. when building project single com.android.application module, android studio use application variant selected in "build variants" menu.

build variants window

this not true library modules, which, if not configured otherwise, publish release build variant – even when select "debug" modules inside "build variants" menu.

to kapt , running library modules, have 3 options:

  1. in "build variants" window, select "release" library module containing annotated code. tell android studio pick kapt output inside generated/sources/kapt/release/.

  2. in library modules build.gradle set defaultpublishconfig debug (and keep selected variant @ debug too). tell android gradle plugin compile debug library variant instead of default release one.

    android {     defaultpublishconfig "debug" } 
  3. you can choose publish both debug , release build variants ant same time, setting publishnondefaults true. in main app module, can reference library module twice, debugcompile , releasecompile configurations. however, note always build both types, though might require debug sources @ time of building, practically doubling compile times.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -