Search code examples
androidannotationspreprocessorjavapoet

Can't resolve method addModifiers in javapoet


I am generating a class using annotation processor in Android. For generating classes, I am using javapoet and it works fine when I use it in java project but in Android I can't access addModifiers method on TypeSpec

 TypeSpec clz = TypeSpec.classBuilder("MyClass")
            .addModifiers(Modifier.PRIVATE)
            .build();

I have imported javax.lang.model.element.Modifier but still it says can't resolve method addModifiers, Modifier parameter of same method in source code is colored red and hovering cursor over it showscan't resolve symbol modifier message. Any solution to this problem?


Solution

  • The Modifier enum isn’t available in Android’s class library. You’ll need to build with a Java SDK instead of the Android SDK.