我尝试在我的子模块中导入kotlin:
项目级别
...
buildscript {
ext.kotlin_version = '1.3.21'
repositories {
jcenter()
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
...
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
...
模块级别
apply plugin: 'kotlin-android'
...
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
...
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
尝试同步后,出现此错误:
ERROR: Unable to resolve dependency for ':app@develop/compileClasspath': Could not resolve project :libraries:Foundation.
Show Details
Affected Modules: app
和堆栈跟踪:
Caused by: java.lang.NullPointerException
at com.google.common.collect.UsingToStringOrdering.compare(UsingToStringOrdering.java:33)
at org.gradle.api.internal.attributes.DefaultDisambiguationRuleChain$ExceptionHandler.handleException(DefaultDisambiguationRuleChain.java:99)
at org.gradle.api.internal.attributes.DefaultDisambiguationRuleChain$ExceptionHandler.handleException(DefaultDisambiguationRuleChain.java:87)
at org.gradle.internal.action.InstantiatingAction.execute(InstantiatingAction.java:44)
at org.gradle.api.internal.attributes.DefaultDisambiguationRuleChain.execute(DefaultDisambiguationRuleChain.java:75)
at org.gradle.api.internal.attributes.DefaultDisambiguationRuleChain.execute(DefaultDisambiguationRuleChain.java:38)
at org.gradle.api.internal.attributes.DefaultAttributesSchema$MergedSchema.disambiguate(DefaultAttributesSchema.java:183)
at org.gradle.internal.component.model.MultipleCandidateMatcher.disambiguateWithAttribute(MultipleCandidateMatcher.java:215)
at org.gradle.internal.component.model.MultipleCandidateMatcher.disambiguateWithRequestedAttributes(MultipleCandidateMatcher.java:202)
at org.gradle.internal.component.model.MultipleCandidateMatcher.disambiguateCompatibleCandidates(MultipleCandidateMatcher.java:192)
at org.gradle.internal.component.model.MultipleCandidateMatcher.getMatches(MultipleCandidateMatcher.java:111)
at org.gradle.internal.component.model.ComponentAttributeMatcher.match(ComponentAttributeMatcher.java:123)
at org.gradle.api.internal.attributes.DefaultAttributesSchema$DefaultAttributeMatcher.matches(DefaultAttributesSchema.java:156)
at org.gradle.internal.component.model.AttributeConfigurationSelector.selectConfigurationUsingAttributeMatching(AttributeConfigurationSelector.java:40)
at org.gradle.internal.component.model.LocalComponentDependencyMetadata.selectConfigurations(LocalComponentDependencyMetadata.java:117)
at org.gradle.internal.component.local.model.DslOriginDependencyMetadataWrapper.selectConfigurations(DslOriginDependencyMetadataWrapper.java:60)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.EdgeState.calculateTargetConfigurations(EdgeState.java:166)
... 105 more
我的gradle版本:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
我进行了很多搜索,但找不到该问题的原因和解决方案。有人遇到过与我相同的问题吗?
答案 0 :(得分:0)
我找到了解决方案,但不知道为什么...
在我的基础模块中
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
以及在我的应用模块中
buildTypes {
...
test {
...
matchingFallbacks = ['release', 'debug']
}
}
在基础模块中的matchingFallbacks或kotlin-plugin中删除“调试”后,它会正常工作。