android-saripaar v2 messageResId 必须是常量

标签 android validation saripaar

我是 java 和 android 开发的新手。我会用 Android Saripaar v2 (thx at Ragunath Jawahar)用于验证。

我使用 Android Studio。

在一个没有其他模块的新的干净的 android 项目上它工作得很好。

但是在我的多模块应用程序中,注释中的 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(模块: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 此文件中的错误

 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";

最佳答案

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

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

关于android-saripaar v2 messageResId 必须是常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29260455/

相关文章:

jquery - 无法使用 [] 验证复选框

wpf - 如何限制wpf文本框中的特殊符号,例如%?

AngularJS 异步验证器 - 来自服务器响应的 UI 验证消息

java - Ionic 2 build android 失败(JDK 1.8 或更高版本的要求检查失败)

android - 当我的任务运行时在状态栏中显示一个图标

android - 使用 Retrofit 2.0 Observables 时出现错误时如何获取响应正文

java - 以编程方式从 android 中的 manifest.xml 中检索权限

Android 6 EditText.setError 无法正常工作

android - Saripaar 的@ConfirmPassword 不工作

android - 编辑文本中的绘图权在错误后不更新