【问题标题】:Build realm sync project with new Android (Java) project使用新的 Android (Java) 项目构建领域同步项目
【发布时间】:2022-01-27 14:23:14
【问题描述】:

我无法让我的领域依赖项适合 Android Java 项目。

我开始a new project 尝试找出问题。

该项目正在使用 Android Gradle Plugin 7.1.0 版和 Gradle 7.2 版以及 Android studio 2021.1.1

我followed the instructions for installing realm in the project。它会在我调用时构建并运行

Realm.init(context);

但是,当我尝试初始化同步领域时(在获取 Sync quick start guide 之后购买),我似乎无法为 App 和 AppConfiguration 类获取正确的导入。

构建失败

error: cannot find symbol
        App app = new App(new AppConfiguration.Builder("XXXYYYZZZ")

在我的旧项目中,我看到导入是

import io.realm.mongodb.App;
import io.realm.mongodb.AppConfiguration;

但这似乎没有被 Android Studio 发现。

(import io.realm.transformer.RealmTransformer 行的 RealmTransformer 部分已读取,这可能不是一个好兆头,但我在 IDE 中看不到任何警告,而且它似乎构建良好)

应用级gradle文件如下

我尝试了api 与implementation 和kapt 与annotationProcessor 的各种组合。还做了“使缓存无效并重新启动”。但没有任何效果。

buildscript {
    ext.kotlin_version = '1.5.21'
    ext.realm_version = '10.10.0'
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "io.realm:realm-transformer:$realm_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

plugins {
    id 'com.android.application'
}

//apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

import io.realm.transformer.RealmTransformer
android.registerTransform(new RealmTransformer(project))


android {
    compileSdk 31

    defaultConfig {
        applicationId "guru.diederik.myapplication"
        minSdk 21
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:2.0.4'

    api "io.realm:realm-annotations:$realm_version"
    api "io.realm:realm-android-library:$realm_version"
    api "io.realm:realm-android-kotlin-extensions:$realm_version"
    kapt "io.realm:realm-annotations-processor:$realm_version"

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

}

【问题讨论】:

    标签: java android gradle android-gradle-plugin realm


    【解决方案1】:

    安装说明似乎已更新。应用它们现在已经成功,并且项目构建。

    有效的项目级 gradle 文件。

    buildscript {
        ext.realm_version = '10.10.1'
        dependencies {
            classpath "io.realm:realm-gradle-plugin:$realm_version"
        }
    }
    
    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    plugins {
        id 'com.android.application' version '7.1.0' apply false
        id 'com.android.library' version '7.1.0' apply false
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    应用级 gradle 文件有效

    buildscript {
        ext.kotlin_version = '1.6.10'
        repositories {
            jcenter()
            mavenCentral()
        }
        dependencies {
            classpath "io.realm:realm-transformer:$realm_version"
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
    plugins {
        id 'com.android.application'
    }
    
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-kapt'
    apply plugin: 'realm-android'
    
    android {
        compileSdk 31
    
        defaultConfig {
            applicationId "guru.diederik.myapplication"
            minSdk 21
            targetSdk 31
            versionCode 1
            versionName "1.0"
    
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }
    
    realm {
        syncEnabled = true
    }
    
    dependencies {
    
        implementation 'com.android.support:appcompat-v7:28.0.0'
        implementation 'com.android.support.constraint:constraint-layout:2.0.4'
    
        testImplementation 'junit:junit:4.13.2'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-27
      • 2018-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多