0

I am getting an error of "attribute value must be constant" although the variable is final.

protected final String APP_PACKAGE = abstractPlatform.getPropertiesReader().getPackageName();

    @AndroidFindBy(id = APP_PACKAGE +":id/btnSignUp")
private MobileElement signUpTab;

if I initialize APP_PACKAGE with a regular String then I am not getting this error. for example: APP_PACKAGE = "com.company.aa"; APP_PACKAGE is final as you can see so why i am getting this error? Anything i miss?

thanks

kidulf
  • 419
  • 1
  • 6
  • 17

1 Answers1

0

Properties of annotations must be compile-time constants and

abstractPlatform.getPropertiesReader().getPackageName();

is only resolvable at runtime. This means APP_PACKAGE is not a compile-time constant.

Michael
  • 41,989
  • 11
  • 82
  • 128
  • is there a way I can make it a compile-time constant besides setting APP_PACKAGE value using a regular string? – kidulf Apr 16 '19 at 11:22
  • @shay7 You could replace the constant at build-time. One example would be [Maven Templating Plugin](http://www.mojohaus.org/templating-maven-plugin/index.html): "*This plugin is useful to filter Java Source Code if you need for example to have things in that code replaced with some properties values*". – Michael Apr 16 '19 at 11:25