'reflections.getTypesAnnotatedWith(TestAnnotation.class) return null

reflections.getTypesAnnotatedWith(TestAnnotation.class) return null at runtime, but when I use it in "java test code" it work perfectly. look at the code below, Annotation class:

@Keep
@Retention(RetentionPolicy.RUNTIME)
public @interface TestAnnotation {
}

this is my test class:

@TestAnnotation
public class test {
}

and this is the code of of searching class with this annotation

public void builder(String packageClasses) {

  
   Reflections reflections = new Reflections(packageXlasses);
   Set<Class<?>> docClasses = reflections.getTypesAnnotatedWith(TestAnnotation.class);


   Log.e("TAG", "builder: docClasses.size: " + docClasses.size());
    System.out.println("builder: docClasses.size: " + docClasses.size());
    for (Class<?> c : docClasses) {
      Log.e("TAG", "builder: c.getName(): " +c.getName());
    }
    
}

package of the test class is : com.myapp.test.model



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source