非法状态异常:期望配置':module:debugFeatureCompileClasspath'仅包含一个文件,但是它包含2个文件。

3
我正在处理一个包含即时应用程序和穿戴应用程序的多功能安卓应用。在这里,我能够成功运行我的应用程序,但是在构建APK或重新构建项目时会出现以下错误。请注意保留HTML标签。
java.lang.IllegalStateException: Expected configuration ':module1:debugFeatureCompileClasspath' to contain exactly one file, however, it contains 2 files.
at org.gradle.api.internal.file.AbstractFileCollection.getSingleFile(AbstractFileCollection.java:62)
at com.android.build.gradle.tasks.MergeManifests.doFullTaskAction(MergeManifests.java:116)
at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:106)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)

我的项目有3-4个模块和一个基础模块项目。我已经按照Google提供的示例集成了多功能即时应用程序的所有设置。 https://github.com/googlesamples/android-instant-apps/tree/master/multi-feature-module 我有一个模块(apimodule),在这个模块中,我添加了所有库和API依赖项。以下是我的项目依赖结构。
  1. AppModule
将所有模块添加为实现。
implementation project(':base')
implementation project(':module1')
implementation project(':module2')
implementation project(':module3')
wearApp project(':wear')
  1. BaseModule(还添加了application project(':app')

在gradle中添加了baseFeature true

feature project(':module1')
feature project(':module2')
feature project(':module3')
api project(':apimodule')

3. apimodule

在gradle中添加了baseFeature true

这是我的一个module1 gradle文件。

apply plugin: 'com.android.feature'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 26
    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.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 project(':base')
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

}

你能分享module1的build.gradle中相关部分吗? - Hassan Ibraheem
是的,已经使用module1 gradle更新了问题。 - Devganiya Hitesh
此外,你能否移除基础模块中重复的 feature project(':module1') - TWL
1
你的问题提到了你在apiModule和BaseModule中都添加了baseFeature true,这是真的吗?我认为你不能在同一个即时应用中拥有两个基础功能。apimodule应该是一个普通的库模块,然后它将被打包在你的baseFeature APK中。 - Hassan Ibraheem
我想你可以将它作为库包含在baseModule中,这样你就会有一个基本的APK,但当然,这取决于项目结构,你的结果可能会有所不同。 - Hassan Ibraheem
显示剩余4条评论
1个回答

2
根据我的问题,我在两个 gradle 文件中添加了 "baseFeature true"。一个是“基础模块”gradle文件,另一个是“API模块”gradle文件,并且将API模块作为依赖项目添加到基础模块中。
我所做的是将API模块的所有代码重构到基础模块中,并仅创建一个带有“baseFeature true”的“基础模块”。
这是唯一解决我的问题的方法。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接