android-saripaar v2 messageResId必须是常量

时间:2015-03-25 15:52:52

标签: android validation saripaar

我是java和android开发的新手。我将使用Android Saripaar v2 (thx at Ragunath Jawahar)进行验证。

我使用Android Studio。

在没有其他模块的新干净安卓项目中,它运行得非常好。

但是在我的多模块应用程序中,我在注释中遇到了 messageResId 属性的问题。 (属性值必须是常量

这是我的代码:

build.gradle(模块:应用)

...
// 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(模块:身份验证)

 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 此文件中的错误

 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 个答案:

答案 0 :(得分:3)

您不能在库模块中使用需要Android资源标识符的注释作为其属性。您只能将它们与应用程序模块一起使用。

库模块中的资源标识符不是最终的。另一方面,应用程序模块中的资源标识符是最终的。 Java注释仅接受属性值的常量(最终变量)。