2 files found with path 'META-INF/LGPL2.11'

19.1k Views Asked by At

Does anybody knows how to debug this? I cannot figure out which libraries are generating the problem.

Side note, it only happens when I try to run Android tests so my best guess is it's related to some testing library.


    testImplementation "androidx.room:room-testing:$version_room"
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0'
    // Compose Tests
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$version_compose"
    debugImplementation "androidx.compose.ui:ui-test-manifest:$version_compose"
    // Hilt test
    androidTestImplementation "com.google.dagger:hilt-android-testing:$version_hilt"
    kaptAndroidTest "com.google.dagger:hilt-android-compiler:$version_hilt"
    debugImplementation 'androidx.fragment:fragment-testing:1.3.6'
Execution failed for task ':app:mergeDebugAndroidTestJavaResource'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
   > 2 files found with path 'META-INF/LGPL2.1' from inputs:
      - /home/lbenevento/.gradle/caches/transforms-3/1e2dfa6057fe4e701d175f47b1099efa/transformed/jetified-jna-platform-5.5.0.jar
      - /home/lbenevento/.gradle/caches/transforms-3/405542266c1c406c39ff1a20cb26a332/transformed/jetified-jna-5.5.0.jar
     Adding a packagingOptions block may help, please refer to
     https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html
     for more information

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:mergeDebugAndroidTestJavaResource'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:187)
    at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:268)
...

This is the full error: https://pastebin.com/74cLGMR9

7

There are 7 best solutions below

3
Alejandro H. Cruz On

This worked out for a similar issue for me:

android {
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/*.properties'
        exclude 'META-INF/AL2.0'
        exclude 'META-INF/LGPL2.1'
    }
}
2
JHowzer On

This happened for me when I added androidTestImplementation "androidx.compose.ui:ui-test-junit4:$version_compose".

Referring to the advice in this posting, I decided to use pickFirst as opposed to exclude.

According to the PackagingOptions documentation, pickFirst will allow for the first occurrence of the file to be packaged with the APK, whereas exclude would exclude all occurrences of the file.

This ended up working for me:

android {
    packagingOptions {
        pickFirst 'META-INF/AL2.0'
        pickFirst 'META-INF/LGPL2.1'
    }
}
3
Timur On

So the exclude and pickFirst already deprecated in kotlin DSL. put the following in your build.gradle.kts:

android {   
    packagingOptions {
        resources.excludes.apply {
            add("META-INF/LICENSE")
            add("META-INF/*.properties")
            add("META-INF/AL2.0")
            add("META-INF/LGPL2.1")
        }
    }
}
0
Rezwan On

I was tried to setup kotlin into my java project and fixed the above issue by adding this into build.gradle

android{
        packagingOptions {
                    resources {
                        excludes += '/META-INF/{AL2.0,LGPL2.1}'
                    }
            }
    }
1
joghm On

this worked for me

  packagingOptions {
        resources {
            resources.excludes.add("/META-INF/{AL2.0,LGPL2.1}")
            resources.excludes.add("META-INF/LICENSE.md")
            resources.excludes.add("META-INF/LICENSE-notice.md")
        }
    }
0
CodeSun On

Try to delete jetified-jna-5.5.0.jar or jetified-jna-platform-5.5.0.jar. One cache import is not necessary.

0
ernesthor On

I hope this will work to others

    packaging.resources {
        pickFirsts += "/META-INF/LICENSE.md"
        pickFirsts += "/META-INF/LICENSE-notice.md"
        pickFirsts += "/META-INF/AL2.0"
        pickFirsts += "/META-INF/LGPL2.1"
    }

But in the end I end up having more problems.

I suggest if you have a interface to the class that your mocking. Just create a fake class and inherit the interface and just return what will you do in mock, it's just the same

For example

interface SomeRepository {
fun getDetails(): SomeModel
fun getApiCall(): Resource<String>
}

Create a fake class

class FakeSomeRepository : SomeRepository {
override fun getDetails(): SomeModel {
return SomeModel() //add model properties here

override fun getApiCall(): Resource<String> {
//create different logic here to return Success, Loading, Error
return Resource.Success("Returned String")
}

And in your test class

class SomeViewModelTest {

private lateinit var someViewModel: SomeViewModel
private lateinit var fakeRepository = FakeSomeRepository()

@Before
fun setup() {
someViewModel = SomeViewModel(fakeRepository)
}

@Test
fun `some test`() = runTest {
assertThat.(someViewModel.getDetails()).isEqualTo(SomeModel())
}
}

it's just a snippet, but I hope it would help anyone who read this. You can also see articles in medium that supports using fakes than mocking.