android-saripaar v2 messageResId must be constant

1.2k Views Asked by At

I am new at java and android development. I will use Android Saripaar v2 (thx at Ragunath Jawahar) for validation.

I use Android Studio.

On a new clean android project with no other modules it work very well.

But on my multi modules Application I have problems with the messageResId property in the annotation. (Attribute value must be constant)

Here my code:

build.gradle (Module: app)

...
// workaround for "duplicate files during packaging of APK" issue
// see https://groups.google.com/d/msg/adt-dev/bl5Rc4Szpzg/wC8cylTWuIEJ
packagingOptions {
    exclude 'META-INF/ASL2.0'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/NOTICE'
}

allprojects {
     repositories {
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "http://files.couchbase.com/maven2/" }
     }
 }

 dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     compile 'com.android.support:appcompat-v7:21.0.3'
     compile 'com.android.support:support-v4:21.0.3'
     compile project(':auth')
 }
...

build.gradle (Module: auth)

 dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'com.android.support:appcompat-v7:21.0.3'
      compile 'com.facebook.android:facebook-android-sdk:3.21.1'
      compile 'com.google.android.gms:play-services:6.5.87'
      compile 'com.mobsandgeeks:android-saripaar:2.0-SNAPSHOT'
      compile project (':other_api_module')
 }

auth/java/.../SignInFragment.java ERROR IN THIS FILE

 public class SignInFragment extends Fragment implements View.OnClickListener, View.OnFocusChangeListener, Validator.ValidationListener{

 String TAG = SignInFragment.class.getName();
 private ISignInFragment iSignInFragment;

 @Email(messageResId = R.string.editTextEmailValidationError) //ERROR: Attribute (R.string.editTextEmailValidationError) value must be constant
 private EditText editTextEmail;
 private EditText editTextPassword;
 static public String EMAIL = "email";
1

There are 1 best solutions below

0
On

You cannot use annotations that require Android resource identifiers for their attributes in library modules. You can only use them with application modules.

Resource identifiers in library modules are not final. On the other hand, resource identifiers in application modules are final. Java annotations accept only constants (final variables) for attribute values.