IllegalStateException: Expected configuration ':module:debugFeatureCompileClasspath' to contain exactly one file, however, it contains 2 files
Asked Answered
H

1

3

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'

}
Homocercal answered 16/5, 2018 at 4:36 Comment(9)
Can you share relevant parts of build.gradle for module1?Partook
Yes updated question with module1 gradle.Homocercal
What com.android.tools.build:gradle are you using? Could you try a different version? developer.android.com/studio/releases/gradle-plugin A search for "to contain exactly one file, however it contains 2 files.", unrelated to instant apps, shows some people resolved it with using a different version.Serrato
Also, can you remove the duplicate feature project(':module1') in your base module.Serrato
@Serrato Already tried but no luck. module1 is my typing mistake.Homocercal
Your question mentions that you added baseFeature true to both apiModule and BaseModule, is this true? I don't think you can have 2 base features in the same instant app. The apimodule should be a normal library module, then it will be shipped within your baseFeature APK.Partook
Just checked the same and i can not remove just baseFeature true from one module. I have to refactor all code of APImodule into base module.Homocercal
I guess you can just include it as a library in baseModule, then you would have one base APK, but your mileage may vary of course, depending on project structure.Partook
Yes done it same already and it worked.Homocercal
H
2

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.

Homocercal answered 17/5, 2018 at 10:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.