【问题标题】:Error after building as release APK but no error with debug APK - Error: Found two getters or fields with conflicting case sensitivity构建为发布 APK 后出错,但调试 APK 没有错误 - 错误:找到两个区分大小写的 getter 或字段
【发布时间】:2019-06-09 14:40:15
【问题描述】:

由于添加了一些功能,我的应用程序在最近重建之前还可以。但是这个添加的功能与新错误无关(这很奇怪)。我什至尝试删除新功能,但现在错误仍然存​​在。它一定是随着 Gradle 或 android studio 的新更新而来的。

我已经检查了这个 POJO 并尽我所能对其进行了修改,但错误仍然存​​在(或者错误更改为同一个 java POJO 文件上的不同变量)。

我还更改了 build.gradle 上的发布选项,使其具有与调试类似的选项,但它仍在发生。

基于这个类似的问题:Firebase No properties to serialize found on class

我已经尝试了那里的所有方法(将模型类保留在 proguard 中,在所述 POJO 模型顶部的 @Keep 注释并将所有变量在 POJO 上公开),但无济于事。

这是我当前的 build.gradle: 调试 {

        minifyEnabled false
        useProguard false
        ext.enableCrashlytics = false
        debuggable true
        shrinkResources false
        jniDebuggable true
        renderscriptDebuggable false
        pseudoLocalesEnabled false
        zipAlignEnabled true
    }
    release {
        minifyEnabled true
        useProguard false
        debuggable false
        shrinkResources true
        jniDebuggable false
        renderscriptDebuggable false
        pseudoLocalesEnabled false
        zipAlignEnabled true
    }

这是受影响的 POJO:

import android.support.annotation.Keep;
import com.google.firebase.firestore.IgnoreExtraProperties;
import com.google.firebase.Timestamp;

@IgnoreExtraProperties
@Keep
public class UIDOrg {
public String Org;
public Timestamp LastEdit;
public String RootCollection;
public Boolean UserRoleDelivery, UserRoleFulfilment, UserRoleOrder, UserRoleVerification, AllowEditOrder, AllowAddOrder;
public Long LocalNotificationReminderTime;

public Long getLocalNotificationReminderTime() {
    return LocalNotificationReminderTime;
}

public Boolean getUserRoleDelivery() {
    return UserRoleDelivery;
}

public Boolean getUserRoleFulfilment() {
    return UserRoleFulfilment;
}

public Boolean getUserRoleOrder() {
    return UserRoleOrder;
}

public Boolean getUserRoleVerification() {
    return UserRoleVerification;
}

public Boolean getAllowEditOrder() {
    return AllowEditOrder;
}

public Boolean getAllowAddOrder() { return AllowAddOrder; }

public String getOrg() {
    return Org;
}

public java.util.Date getLastEdit() {
    return LastEdit.toDate();
}

public String getRootCollection() {
    return RootCollection;
}

public UIDOrg(String org, Timestamp lastEdit, String rootCollection, Boolean userRoleDelivery, Boolean userRoleFulfilment, Boolean userRoleOrder, Boolean userRoleVerification, Boolean allowEditOrder, Boolean allowAddOrder, Long localNotificationReminderTime) {
    Org = org;
    LastEdit = lastEdit;
    RootCollection = rootCollection;
    UserRoleDelivery = userRoleDelivery;
    UserRoleFulfilment = userRoleFulfilment;
    UserRoleOrder = userRoleOrder;
    UserRoleVerification = userRoleVerification;
    AllowEditOrder = allowEditOrder;
    AllowAddOrder = allowAddOrder;
    LocalNotificationReminderTime = localNotificationReminderTime;
}

public UIDOrg() {
}
}

这是我在构建(捆绑包和 APK)作为发布后现在得到的错误:

java.lang.RuntimeException: Found two getters or fields with conflicting case sensitivity for property: allowaddorder
    at d.e.c.f.g.j$a.a(Unknown Source:44)
    at d.e.c.f.g.j$a.<init>(:6)
    at d.e.c.f.g.j.a(Unknown Source:12)
    at d.e.c.f.g.j.a(:16)
    at d.e.c.f.g.j.a(Unknown Source:2)
    at d.e.c.f.g.a(Unknown Source:18)
    at d.e.c.f.g.a(Unknown Source:2)
    at d.f.a.b.a.a(:1)
    at d.e.a.a.l.w.run(:6)
    at android.os.Handler.handleCallback(Handler.java:891)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:207)
    at android.app.ActivityThread.main(ActivityThread.java:7470)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)

该错误与“没有要序列化的属性”不同,但我之前在删除 proguard 支持时也遇到了该错误。

【问题讨论】:

    标签: java android firebase pojo


    【解决方案1】:

    您的变量需要采用camelCase 格式,然后您可以执行以下操作:

    public class UIDOrg {
    
            public String org;
            public Timestamp lastEdit;
            public String rootCollection;
            public Boolean userRoleDelivery, userRoleFulfilment, userRoleOrder, userRoleVerification, allowEditOrder, allowAddOrder;
            public Long localNotificationReminderTime;
    
        public UIDOrg() {
        }
    
        public UIDOrg(String org, Timestamp lastEdit, String rootCollection, Boolean userRoleDelivery, Boolean userRoleFulfilment, Boolean userRoleOrder, Boolean userRoleVerification, Boolean allowEditOrder, Boolean allowAddOrder, Long localNotificationReminderTime) {
            this.org = org;
            this.lastEdit = lastEdit;
            this.rootCollection = rootCollection;
            this.userRoleDelivery = userRoleDelivery;
            this.userRoleFulfilment = userRoleFulfilment;
            this.userRoleOrder = userRoleOrder;
            this.userRoleVerification = userRoleVerification;
            this.allowEditOrder = allowEditOrder;
            this.allowAddOrder = allowAddOrder;
            this.localNotificationReminderTime = localNotificationReminderTime;
        }
    
        public String getOrg() {
            return org;
        }
    
        public void setOrg(String org) {
            this.org = org;
        }
    
        public Timestamp getLastEdit() {
            return lastEdit;
        }
    
        public void setLastEdit(Timestamp lastEdit) {
            this.lastEdit = lastEdit;
        }
    
        public String getRootCollection() {
            return rootCollection;
        }
    
        public void setRootCollection(String rootCollection) {
            this.rootCollection = rootCollection;
        }
    
        public Boolean getUserRoleDelivery() {
            return userRoleDelivery;
        }
    
        public void setUserRoleDelivery(Boolean userRoleDelivery) {
            this.userRoleDelivery = userRoleDelivery;
        }
    
        public Boolean getUserRoleVerification() {
            return userRoleVerification;
        }
    
        public void setUserRoleVerification(Boolean userRoleVerification) {
            this.userRoleVerification = userRoleVerification;
        }
    
        public Boolean getAllowAddOrder() {
            return allowAddOrder;
        }
    
        public void setAllowAddOrder(Boolean allowAddOrder) {
            this.allowAddOrder = allowAddOrder;
        }
    
        public Long getLocalNotificationReminderTime() {
            return localNotificationReminderTime;
        }
    
        public void setLocalNotificationReminderTime(Long localNotificationReminderTime) {
            this.localNotificationReminderTime = localNotificationReminderTime;
        }
    
        public Boolean getAllowEditOrder() {
            return allowEditOrder;
        }
    
        public void setAllowEditOrder(Boolean allowEditOrder) {
            this.allowEditOrder = allowEditOrder;
        }
    
        public Boolean getUserRoleFulfilment() {
            return userRoleFulfilment;
        }
    
        public void setUserRoleFulfilment(Boolean userRoleFulfilment) {
            this.userRoleFulfilment = userRoleFulfilment;
        }
    
        public Boolean getUserRoleOrder() {
            return userRoleOrder;
        }
    
        public void setUserRoleOrder(Boolean userRoleOrder) {
            this.userRoleOrder = userRoleOrder;
        }
    }
    

    【讨论】:

    • 感谢您的回答。它有效,但现在我必须更改我的 firebase 中的每个字段名称以匹配 camelCase。
    • 问题:为什么只在这个模型中需要它?我喜欢其他 4 种不使用 camelCase 的模型。
    • 不确定其他模型是如何工作的,但您应该始终遵循 java 命名约定 oracle.com/technetwork/java/codeconventions-135099.html,以便 firebase 数据库可以序列化您的模型
    • 知道了 :-) 在这里我的时区晚上得到了答案。谢谢@PeterHaddad
    猜你喜欢
    • 2019-09-26
    • 2018-06-25
    • 1970-01-01
    • 2020-08-17
    • 2016-07-02
    • 2017-03-13
    • 2016-10-14
    • 2020-08-24
    • 2018-08-13
    相关资源
    最近更新 更多