【问题标题】:How to install realm as a gradle dependency?如何将领域安装为 gradle 依赖项?
【发布时间】:2016-03-16 06:18:02
【问题描述】:

我对领域完全陌生。我想在我的 android 项目中使用领域数据库。我通过了官方Realm documentation。我需要在我的 android 项目中设置领域。为此,我将 gradle 依赖添加为

    buildscript {
            repositories {
                     jcenter()
                         }
            dependencies {
                classpath "io.realm:realm-gradle-plugin:0.88.2"
           }
       }
 apply plugin: 'realm-android'

这是他们在文档中给出的。但这对我不起作用。它给出了错误提示Plugin with id 'realm-android' not found

这是我的 build.gradle 文件

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.db.realmsample"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "io.realm:realm-gradle-plugin:0.88.2"
    }
  }

 }

 dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:appcompat-v7:23.2.1'
  }

我的配置正确吗?

【问题讨论】:

    标签: android realm


    【解决方案1】:

    buildscript 移动到您的主 build.gradle 文件 (Project) 中,它不应该在 build.gradle (module:app) 中

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

    这应该转到 main build.gradle

    【讨论】:

    【解决方案2】:

    首先将类路径依赖复制到build.gradle文件(Project)中:-

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

    最后,将以下代码复制并粘贴到 build.gradle(App) 之上:-

    apply plugin: 'realm-android'
    

    注意:- 1.2.0 版本可能会在以后的版本中发生变化。更多信息请查看https://realm.io/docs/java/latest/

    【讨论】:

    • 感谢链接,了解配置和最新版本号很有帮助!
    • @MuSa Android SDK 23
    【解决方案3】:

    先决条件

    • Android Studio 1.5.1 或更高版本
    • JDK 7.0 或更高版本
    • Android SDK 的最新版本
    • Android API 级别 9 或更高版本(Android 2.3 及更高版本)

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

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

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

    apply plugin: 'realm-android'
    

    第 3 步: Gradle 同步

    获取官方完整安装指南。请参阅以下链接。

    https://realm.io/docs/java/latest/#installation

    【讨论】:

      【解决方案4】:

      我使用的方法是

         `     dependencies 
      {
              classpath 'com.android.tools.build:gradle:3.0.0'
              classpath "io.realm:realm-gradle-plugin:3.1.4"
      
          }`
      

      在您的主要构建 gradle 文件中 然后添加

      apply plugin: 'realm-android'
      

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

      在您应用的构建 gradle 中

      这个指向 bintray 的链接将为您提供最新版本 https://bintray.com/realm/maven/realm-android-library/3.4.0#files/io%2Frealm%2Frealm-android-library%2F3.4.0

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-07
        • 1970-01-01
        • 2011-10-15
        • 1970-01-01
        • 2019-01-04
        • 1970-01-01
        相关资源
        最近更新 更多