Android领域无法解析符号SyncCredentials,SyncUser,ObjectServerError。但Realm,RealmObject ..类工作正常

时间:2017-10-03 07:53:53

标签: android realm realm-mobile-platform realm-object-server

我从Realm objectServerExample获取了代码。

SyncCredentials creds = SyncCredentials.usernamePassword(username, password, createUser);
        SyncUser.Callback<SyncUser> callback = new SyncUser.Callback<SyncUser>() {
            @Override
            public void onSuccess(@Nonnull SyncUser user) {
                progressDialog.dismiss();
                onLoginSuccess();
            }

            @Override
            public void onError(@Nonnull ObjectServerError error) {
                progressDialog.dismiss();
                String errorMsg;
                switch (error.getErrorCode()) {
                    case UNKNOWN_ACCOUNT:
                        errorMsg = "Account does not exists.";
                        break;
                    case INVALID_CREDENTIALS:
                        errorMsg = "User name and password does not match";
                        break;
                    default:
                        errorMsg = error.toString();
                }
                onLoginFailed(errorMsg);
            }
        };

它说Cannot resolve symbol SyncCredentials

io.realm.Realm课程正在发挥作用。

我的项目级别gradle文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath "io.realm:realm-gradle-plugin:3.7.2"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'

        classpath 'me.tatarka:gradle-retrolambda:3.7.0'
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Gradle(模块:app)

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'me.tatarka.retrolambda'

android {
    compileSdkVersion 26
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.amit.database"
        minSdkVersion 22
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//        jackOptions {
//            enabled true
//        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'

    compile 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

    compile "android.arch.lifecycle:runtime:1.0.0-alpha9"
    compile "android.arch.lifecycle:extensions:1.0.0-alpha9"
    annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha9"

    compile group: 'com.google.guava', name: 'guava', version: '22.0-android' // or 22.0-android for the Android flavor
    compile 'com.android.support:design:25.3.1'
}

主要目标是在aws-ec2上将Android应用程序与领域对象服务器连接起来。它工作正常,可以从浏览器访问。

1 个答案:

答案 0 :(得分:2)

添加

realm {
    syncEnabled = true
}
gradle(module:app)中的

使用领域同步功能

最终Gradle(模块:app)

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'me.tatarka.retrolambda'

android {
    compileSdkVersion 26
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.amit.database"
        minSdkVersion 22
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//        jackOptions {
//            enabled true
//        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }
}
realm {
    syncEnabled = true
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'

    compile 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

    compile "android.arch.lifecycle:runtime:1.0.0-alpha9"
    compile "android.arch.lifecycle:extensions:1.0.0-alpha9"
    annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha9"

    compile group: 'com.google.guava', name: 'guava', version: '22.0-android' // or 22.0-android for the Android flavor
    compile 'com.android.support:design:25.3.1'
}