Firebase监听器在APK中的行为与Android Studio

时间:2016-09-05 21:19:22

标签: android firebase apk firebase-realtime-database event-listener

我正在构建一个app,应用程序会监听firebase更新并做出响应。我的应用程序在从Android Studio以调试模式运行时运行得非常好,但是当我构建已签名的APK并从我的手机运行它时,它无法正常工作。

具体来说,这段代码:

weightListener = weights.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                weightVals = dataSnapshot.getValue(TrainingWeights.class);
            }

            @Override
            public void onCancelled(DatabaseError error) {
                message.setText("Weight event listener error");
            }

        });

TrainingWeights类有两个字段:双打列表和一个int值。在Android Studio版本中,一切都正常更新,但当它从移动设备作为APK运行时,无论实际值是什么,int值始终返回0。我尝试将它更改为像Integer这样的对象类,但是当我这样做时,它总是返回' undefined' (它仍可在Android Studio中正常运行)。我不知道导致问题的原因,特别是因为我的代码中有其他听众没有任何问题。

这是我的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "[id]"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.firebase:firebase-client-android:2.5.1+'
    compile 'com.google.firebase:firebase-auth:9.0.0'
    compile 'com.google.firebase:firebase-database:9.0.0'
}

apply plugin: 'com.google.gms.google-services'

这是TrainingWeights课程:

public class TrainingWeights {
    List<Double> weights;
    int iteration;

    public TrainingWeights(){

    }

    public List<Double> getWeights(){
        return weights;
    }

    public void setWeights(List<Double> weightValues){
        weights = weightValues;
    }

    public int getCurrentIteration(){
        return iteration;
    }

    public void setCurrentIteration(int iteration){
        this.iteration = iteration;
    }


}

0 个答案:

没有答案