gpt4 book ai didi

android - 无法使用 kotlin 将 Realm 集成到 android 库模块中

转载 作者:IT老高 更新时间:2023-10-28 13:42:02 27 4
gpt4 key购买 nike

我的顶级 build.gradle

apply plugin: 'kotlin'


buildscript {
ext.kotlin_version = '1.3.30'
repositories {
mavenLocal()
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
//region realm
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }
//endregion
}
dependencies {
//region google()
classpath 'com.android.tools.build:gradle:3.3.2'
//endregion
//region jcenter()
classpath 'com.google.gms:google-services:4.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

//endregion
//region maven { url 'https://maven.fabric.io/public' }
//to check fabric gradle ver
//https://s3.amazonaws.com/fabric-artifacts/public/io/fabric/tools/gradle/maven-metadata.xml
classpath 'io.fabric.tools:gradle:1.+'
//endregion
//region realm
classpath "io.realm:realm-gradle-plugin:5.8.0"
//endregion
}
}

这是我的库模块 build.gradle

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'realm-android'

android {
...

defaultConfig {
...
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:appcompat-v7:${supportLibVer}"

implementation "io.reactivex:rxjava:${rxJavaVersion}"
implementation("io.reactivex:rxandroid:${rxAndroidVersion}") {
exclude group: 'io.reactivex', module: 'rxjava'
}

implementation("com.github.davidmoten:rxjava-extras:${rxExtrasVersion}") {
exclude group: 'io.reactivex', module: 'rxjava'
}

implementation('io.reactivex:rxjava-math:1.0.0') {
exclude group: 'io.reactivex', module: 'rxjava'
}

implementation "com.google.dagger:dagger:${daggerVersion}"
implementation("com.google.dagger:dagger-android-support:${daggerVersion}") {
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.android.support', module: 'support-fragment'
}
annotationProcessor "com.google.dagger:dagger-compiler:${daggerVersion}"
kapt "com.google.dagger:dagger-compiler:${daggerVersion}"
annotationProcessor "com.google.dagger:dagger-android-processor:${daggerVersion}"
kapt "com.google.dagger:dagger-android-processor:${daggerVersion}"
implementation "javax.inject:javax.inject:${javaxInjectVersion}"
implementation "javax.annotation:jsr250-api:${javaxAnnotationVersion}"
implementation "com.android.support:support-annotations:${supportLibVer}"

...
}

结果我无法同步,错误是:

ERROR: Unable to resolve dependency for ':module@debug/compileClasspath': Could not resolve all dependencies for configuration ':module:debugCompileClasspath'.
Show Details
Affected Modules: module

但是如果我远程

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

然后一切正常

发现问题:这是因为我有 failOnVersionConflict() 在顶部构建 gradle

最佳答案

要解决此问题:顶部 build.gradle 文件:

buildscript {
ext.kotlin_version = '1.3.31'
repositories {
mavenLocal()
google()
jcenter()

//region realm
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }
maven { url 'https://dl.bintray.com/realm/maven' }
//endregion
}
dependencies {
//region google()
classpath 'com.android.tools.build:gradle:3.3.2'
//endregion
//region jcenter()
classpath 'com.google.gms:google-services:4.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

//endregion

//region realm
classpath "io.realm:realm-gradle-plugin:5.11.0"
//endregion
}
}

allprojects {
...

configurations.all {
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jre7'

resolutionStrategy {
// fail eagerly on version conflict (includes transitive dependencies)
// e.g. multiple different versions of the same dependency (group and name are equal)
failOnVersionConflict()

//this is needed:
force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version",
"org.jetbrains.kotlin:kotlin-android-extensions-runtime:$kotlin_version",
"org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version",

}
}
}

关于android - 无法使用 kotlin 将 Realm 集成到 android 库模块中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55810584/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com