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.
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.
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:
in "build variants" window, select "release" library module containing annotated code. tell android studio pick
kapt
output insidegenerated/sources/kapt/release/
.in library modules
build.gradle
setdefaultpublishconfig
debug
(and keep selected variant @ debug too). tell android gradle plugin compiledebug
library variant instead of defaultrelease
one.android { defaultpublishconfig "debug" }
you can choose publish both
debug
,release
build variants ant same time, settingpublishnondefaults
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
Post a Comment