无法在Android Studio的build.gradle中安装Realm。

huangapple go评论67阅读模式
英文:

Unable to install Realm in build.gradle in android studio

问题

我想在Android Studio中为一个Java项目安装Realm,但没有成功。

我期望的是

buildscript {

    repositories {
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0'
    }
}

allprojects {
    repositories {
        google()
    }
}

但我得到了这个。

这是build.gradle(Project: NoteTaking)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.3.0' apply false
    id 'com.android.library' version '7.3.0' apply false
}

这是build.gradle(Module: NoteTaking)

plugins {
    id 'com.android.application'
}

android {
    namespace 'com.example.notetaking'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.notetaking"
        minSdk 21
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.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 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.8.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

这是settings.gradle (Project settings)

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}
rootProject.name = "NoteTaking"
include ':app'

我已尝试将Gradle JDK更改为11,我目前正在使用Android Studio默认的JDK。

英文:

I want to install Realm in android studio for a java project, and It hasnt being sucessfull.

I was expecting

buildscript {

    repositories {
        google()
    }


    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0'
    }
}


allprojects {
    repositories {
        google()
    }
}

But I got this.

This is the build.gradle(Project: NoteTaking)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.3.0' apply false
    id 'com.android.library' version '7.3.0' apply false
}

This is the build.gradle(Module: NoteTaking)

plugins {
    id 'com.android.application'
}

android {
    namespace 'com.example.notetaking'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.notetaking"
        minSdk 21
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.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 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.8.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

}

THis is the settings.gradle (Project settings)

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}
rootProject.name = "NoteTaking"
include ':app'

I have tried changing the Gradle JDK to 11, I am currntly on andriod studio default JDK

答案1

得分: 1

我最终成功解决了我的问题。
以下是我是如何做到的。

build.gradle(Project NoteTaking)中,我用以下代码替换了所有内容:

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

plugins {
    id 'com.android.application' version '7.1.2' apply false
    id 'com.android.library' version '7.1.2' apply false
}

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

build.gradle(Module: NoteTaking.app)中,我添加了以下内容:

plugins {
    id 'realm-android'
}

然后在 plugins 结尾标签之后立即添加:

apply plugin: "realm-android"


<details>
<summary>英文:</summary>

I was able to finally solve my problem.
Here is how I did it.


in the 

&gt; build.gradle(Project NoteTaking)

I replaced all code with

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath &quot;io.realm:realm-gradle-plugin:10.11.1&quot;
        }
    }
    
    plugins {
        id &#39;com.android.application&#39; version &#39;7.1.2&#39; apply false
        id &#39;com.android.library&#39; version &#39;7.1.2&#39; apply false
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }


in the 
&gt; build.gradle(Module: NoteTaking.app)

I added

&gt; id &#39;realm-android&#39;

to plugins

and then apply

&gt; apply plugin: &quot;realm-android

immediatly after the plugins closing tag

    plugins {
        id &#39;com.android.application&#39;
        id &#39;realm-android&#39;
    }
    
    apply plugin: &quot;realm-android&quot;





</details>



huangapple
  • 本文由 发表于 2023年3月4日 08:16:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75632863.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定