Gradle错误:“将配置':app:api'的依赖项包含在依赖项解析后,无法更改。”

时间:2018-07-29 20:22:02

标签: android gradle kotlin android-gradle realm

我之前问过question about a problem with Realm。在那里发表评论,并仔细研究以下解决方案:

solution 1solution 2

让我相信,如果我对应用程序build.gradle文件重新排序,将apply plugin: 'realm-android'放在其他apply plugin语句之后,那么我的问题将得到解决。

但是,如果我尝试得到错误消息:

Cannot change dependencies of configuration ':app:api' after it has been included in dependency resolution.

任何想法如何解决该问题?

这是我的Gradle文件:

应用程序级别:

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlinx-serialization'
apply plugin: 'kotlin-kapt'


android {
compileSdkVersion 26
defaultConfig {
    applicationId "uk.co.davechambers.pegboard"
    targetSdkVersion 26
    minSdkVersion 21
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary= true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

repositories {
google()
jcenter()
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url "http://jcenter.bintray.com"}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.0.0-beta2'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:design:26.0.0-beta2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-vector-drawable:26.0.0-beta2'
implementation "org.jetbrains.anko:anko:$anko_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"

}

kotlin {
experimental {
    coroutines "enable"
}
}

androidExtensions {
experimental = true
}

realm {
syncEnabled = true;
}

和项目级别:

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

buildscript {
ext.kotlin_version = '1.2.40'
ext.anko_version = '0.10.5'
ext.serialization_version = '0.4.1'
repositories {
    google()
    jcenter()
    maven { url "https://kotlin.bintray.com/kotlinx" }
    maven { url "http://jcenter.bintray.com"}
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.3'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath "org.jetbrains.kotlinx:kotlinx-gradle-serialization-plugin:$serialization_version"
    classpath "io.realm:realm-gradle-plugin:5.4.0"

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

}

allprojects {
repositories {
    google()
    jcenter()
    mavenCentral()

}
}

apply plugin: 'kotlin'
apply plugin: 'kotlinx-serialization'

在重复问题之后,我有以下Project level build.gradle

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

buildscript {
ext.kotlin_version = '1.2.40'
ext.realm_version = '5.4.0'
ext.anko_version = '0.10.5'
ext.serialization_version = '0.4.1'

repositories {
    google()
    jcenter()
    maven { url "https://kotlin.bintray.com/kotlinx" }
    maven { url "http://jcenter.bintray.com"}
}

dependencies {
    classpath "io.realm:realm-transformer:5.1.0"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.android.tools.build:gradle:3.1.3'
    classpath "org.jetbrains.kotlinx:kotlinx-gradle-serialization-plugin:$serialization_version"

}
}


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

以及以下App level build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlinx-serialization'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "uk.co.davechambers.pegboard"
    targetSdkVersion 26
    minSdkVersion 21
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary= true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

repositories {
google()
jcenter()
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url "http://jcenter.bintray.com"}
}

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

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.0.0-beta2'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:design:26.0.0-beta2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-vector-drawable:26.0.0-beta2'
implementation "org.jetbrains.anko:anko:$anko_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
implementation "io.realm:realm-annotations:$realm_version"
implementation "io.realm:realm-android-library:$realm_version"
implementation "io.realm:realm-android-kotlin-extensions:$realm_version" {
    exclude group: "org.jetbrains.kotlin", module: "kotlin-stdlib-jdk7"
}
kapt "io.realm:realm-annotations-processor:$realm_version"

}

kotlin {
experimental {
    coroutines "enable"
}
}

androidExtensions {
experimental = true
}

realm {
syncEnabled = true;
}

但是我得到了错误:

Could not find method io.realm:realm-android-kotlin-extensions:5.4.0() for arguments [build_7224x5l18df45vs4q13bacmrt$_run_closure3$_closure13@28920d7a] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

有人可以调整我的gradle文件以使它正常工作吗?

0 个答案:

没有答案
相关问题