1

I earlier asked a question about a problem with Realm. A comment there and a closer look at the following solutions:

solution 1, solution 2

leads me to believe that if I reorder my app build.gradle file to put apply plugin: 'realm-android' after the other apply plugin statements then my problem will be solved.

However, if I try that I get the error:

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

Any ideas how to solve the issue?

Here are my Gradle files:

App level:

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;
}

And Project level:

// 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'

Following the duplicate question, I have the following 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()
}
}

And the following 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;
}

But I get the error:

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.

Can anybody tweak my gradle files to get this thing working?

Dave Chambers
  • 2,483
  • 2
  • 32
  • 55

0 Answers0