英文:
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
> build.gradle(Project NoteTaking)
I replaced all code with
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
}
in the
> build.gradle(Module: NoteTaking.app)
I added
> id 'realm-android'
to plugins
and then apply
> apply plugin: "realm-android
immediatly after the plugins closing tag
plugins {
id 'com.android.application'
id 'realm-android'
}
apply plugin: "realm-android"
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论