IllegalStateException: Expected configuration '

2019-05-11 09:25发布

问题:

I am working with multi feature android application with instant app and wear app.Here i am able to successfully run my application but getting following error during building APK or rebuild projects.

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)

My project has 3-4 module and one base module projects. I have already integrated all setup for multi feature instant app as per sample provide by google. https://github.com/googlesamples/android-instant-apps/tree/master/multi-feature-module

I have one module(apimodule) where i have added all libraries and API dependencies. Following is my project dependencies structure.

  1. AppModule

Added all module as implementation

implementation project(':base')
implementation project(':module1')
implementation project(':module2')
implementation project(':module3')
wearApp project(':wear')
  1. BaseModule ( Also added application project(':app') )

Added baseFeature true in gradle

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

3. apimodule

Added baseFeature true in gradle

Here is my one module1 gradle file.

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'

}

回答1:

As per my question I have added baseFeature true in two gradle files. One of base module gradle and one API module gradle and API module added as dependency project in base module.

What I have done is that refactor all code of API module into base module and make only one base module with baseFeature true.

This is only case solved my problem.