我的顶级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
答案 0 :(得分:5)
要解决此问题,请执行以下操作: 顶部 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",
}
}
}
答案 1 :(得分:1)
将您的根build.gradle
更改为
apply plugin: 'kotlin'
buildscript {
ext.kotlin_version = '1.3.31'
repositories {
google()
jcenter()
maven {
url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.google.gms:google-services:4.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.realm:realm-gradle-plugin:5.11.0-SNAPSHOT"
}
}
allprojects {
repositories {
jcenter()
google()
maven {
url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
}
}
}
,它应该可以正常工作(它确实在我的示例项目中同步了)。请注意您忘记的allprojects
块。另外,您应该apply plugin: 'kotlin-kapt'
结束。
答案 2 :(得分:1)
我当前正在将Realm
与Kotlin
一起使用。这是我的gradle
文件。
应用Kotlin-kapt
中kotlin-android-extensions
和gradle
的顺序似乎应该切换。检查下面
应用gradle
文件:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
android {
compileSdkVersion 28
defaultConfig {
applicationId "xxx"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha03'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
implementation 'com.google.android.material:material:1.1.0-alpha04'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
testImplementation 'junit:junit:4.12'
implementation 'com.google.firebase:firebase-core:16.0.1'
// Add dependency
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'
}
apply plugin: 'com.google.gms.google-services'
根级别gradle
文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.71'
ext.lifecycle_version = '2.0.0'
ext.anko_version='0.10.8'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.google.gms:google-services:4.0.1'
classpath 'com.android.tools.build:gradle:3.2.1'
// Add dependency
classpath 'io.fabric.tools:gradle:1.26.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.realm:realm-gradle-plugin:5.10.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}