gradle 找到2个路径为“META-INF/LGPL2.11”的文件

gz5pxeao  于 2022-12-23  发布在  其他
关注(0)|答案(5)|浏览(399)

有人知道如何调试这个吗?我不知道是哪个库产生了这个问题。
边注,它只发生在我试图运行Android测试,所以我最好的猜测是它与一些测试库。

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)
...

这是完整的错误:https://pastebin.com/74cLGMR9

shyt4zoc

shyt4zoc1#

当我添加androidTestImplementation "androidx.compose.ui:ui-test-junit4:$version_compose"时,我就发生了这种情况。
参考了this posting中的建议,我决定使用pickFirst而不是exclude
根据PackagingOptions documentationpickFirst将允许第一次出现的文件与APK打包在一起,而exclude将排除所有出现的文件。
这对我很有效:

android {
    packagingOptions {
        pickFirst 'META-INF/AL2.0'
        pickFirst 'META-INF/LGPL2.1'
    }
}
b1payxdu

b1payxdu2#

因此excludepickFirst已经在KotlinDSL中弃用。请在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")
        }
    }
}
rur96b6h

rur96b6h3#

这对我来说也是一个类似的问题:

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

1l5u6lss4#

我尝试将Kotlin设置到我的java项目中,并通过将其添加到build.gradle中修复了上述问题

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

tvokkenx5#

这对我很有效

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")
        }
    }

相关问题