【发布时间】:2019-11-11 06:24:27
【问题描述】:
我将com.eftimoff:android-pathview:1.0.8@aar 添加到我的项目中,但是当我运行应用程序时出现此错误:
原因:重复条目:META-INF/MANIFEST.MF
这是外部库中的pathview 文件:
现在我想排除 META-INF 文件夹,所以我将它添加到模块 gradle 中:
android {
...
packagingOptions {
exclude 'META-INF/*'
}
}
但我仍然遇到上述错误。
我写了像this suggestion这样的gradle脚本
当我以这种方式添加库时:
implementation ('com.eftimoff:android-pathview:1.0.8@aar').exclude("META-INF/MANIFEST.MF")
我收到了这个错误:
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\Projects\Android\Mvvm\Kotlin\MovieDb\app\build.gradle' line: 80
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method leftShift() for arguments [build_37vlhf9la1wtl8koroxp1kll7$_run_closure4@b32cc6a] on task ':app:excludeTask' of type org.gradle.api.DefaultTask.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
CONFIGURE FAILED in 0s
Could not find method leftShift() for arguments [build_37vlhf9la1wtl8koroxp1kll7$_run_closure4@b32cc6a] on task ':app:excludeTask' of type org.gradle.api.DefaultTask.
Open File
这是tasks.create("excludeTask") << { 我出错的地方。
所以我把task.create()改成了这个:
tasks.create("excludeTask") {
doLast{
exclusions.each {
File file = file("${buildDir}/intermediates/exploded-aar/${it}")
println("Excluding file " + file)
if (file.exists()) {
file.delete()
}
}
}
}
这些错误消失了,但我仍然再次收到此错误:
原因:重复条目:META-INF/MANIFEST.MF
这个脚本似乎在 resources 上工作,现在我想排除文件夹中的一个文件。
这是完整的 gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
// Enables data binding.
dataBinding {
enabled = true
}
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.t.moviedb"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
// packagingOptions {
// exclude '/META-INF/*'
// }
// aaptOptions {
// ignoreAssetsPattern "!META-INF/MANIFEST.MF"
// ignoreAssetsPattern "META-INF/MANIFEST.MF"
// }
}
final List<String> exclusions = [];
Dependency.metaClass.exclude = { String[] currentExclusions ->
currentExclusions.each {
exclusions.add("${getGroup()}/${getName()}/${getVersion()}/${it}")
}
return thisObject
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// Support libraries
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.fragment:fragment:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// Android KTX
implementation 'androidx.core:core-ktx:1.1.0'
// Testing
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//other
implementation ('com.eftimoff:android-pathview:1.0.8@aar').exclude("META-INF/*")
}
tasks.create("excludeTask") {
doLast{
exclusions.each {
File file = file("${buildDir}/intermediates/exploded-aar/${it}")
println("Excluding file " + file)
if (file.exists()) {
file.delete()
}
}
}
}
tasks.whenTaskAdded({
if (it.name.matches(/^process.*Resources$/)) {
it.dependsOn excludeTask
}
})
这是我的 gradle 版本:
\MovieDb>gradlew --version
------------------------------------------------------------
Gradle 5.4.1
------------------------------------------------------------
Build time: 2019-04-26 08:14:42 UTC
Revision: 261d171646b36a6a28d5a19a69676cd098a4c19d
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_231 (Oracle Corporation 25.231-b11)
OS: Windows 10 10.0 amd64
和:
【问题讨论】:
-
这不行吗? packagingOptions { exclude 'META-INF/MANIFEST.MF' } 注意路径的开头没有前导 /
-
我使用了
exclude 'META-INF/MANIFEST.MF,但我得到了Cause: duplicate entry: META-INF/MANIFEST.MF错误@DanielZolnai -
您使用的是 Gradle Android 插件 3.5.2 吗?如果是,您可以尝试降级到 3.5.1 吗? (不是 Studio,只是插件版本)
-
是的,我正在使用 gradle 3.5.2
classpath 'com.android.tools.build:gradle:3.5.2'并且还更新了我的帖子@DanielZolnai -
从您的 libs/ 中删除 android-pathview-1.0.8.aar 并重试。