【问题标题】:How to implement Realm database in android library?如何在android库中实现Realm数据库?
【发布时间】:2018-07-13 12:30:02
【问题描述】:

将 Realm 安装为 Gradle 插件。

第一步:将类路径依赖添加到项目级别的build.gradle文件中。

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "io.realm:realm-gradle-plugin:5.3.1"
    }
}

第 2 步:将 realm-android 插件应用到应用程序级 build.gradle 文件的顶部。

apply plugin: 'realm-android'

第三步:添加依赖

 implementation 'io.realm:android-adapters:2.0.0'

但是当我构建我的项目时发现这个错误:

配置“编译”已过时,已替换为“实现”和“API”。

完整的 build.gradle(Module) 文件。

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.myfirastapp"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:design:28.0.0-alpha3'
    implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
    implementation 'com.github.bumptech.glide:glide:3.7.0'
    implementation 'io.realm:android-adapters:2.0.0'
}

和 build.gradle(项目)

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

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath "io.realm:realm-gradle-plugin:3.1.4"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

【问题讨论】:

  • 请分享您的完整 gradle 文件
  • 是的,我已经在我的问题上更新了我的项目和模块的完整 gradle 文件
  • 编译 'io.realm:android-adapters:2.0.0' 请最后用实现 'io.realm:android-adapters:2.0.0' 更改它
  • 改了还是一样的错误

标签: android android-gradle-plugin


【解决方案1】:

将 gradle 文件中的所有“编译”替换为“实现”

【讨论】:

    猜你喜欢
    • 2016-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    • 1970-01-01
    • 1970-01-01
    • 2016-07-16
    相关资源
    最近更新 更多