Gradle duplicate entry error: META-INF/MANIFEST.MF (Or how to delete a file from jar)
Gradle duplicate entry error: META-INF/MANIFEST.MF (Or how to delete a file from jar)
我已经克隆了一个 github 存储库,因为我想研究代码,但是当我尝试在 Android Studio 中构建它时,我 运行 遇到了一些麻烦。
添加 google maven 存储库(由 Android Studio 提示)并更新 Gradle 插件版本和成绩版本(分别为 3.5.2 和 5.4.1)后,由于以下错误,构建失败:
Cause: duplicate entry: META-INF/MANIFEST.MF
这个,更具体地说:
Caused by: java.util.zip.ZipException: duplicate entry: META-INF/MANIFEST.MF
这是我的项目级别build.gradle文件:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}
}
这是我的模块 build.gradle 文件(在尝试之前):
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.thelittlenaruto.supportdesignexample"
minSdkVersion 11
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation ('com.android.support:appcompat-v7:22.2.1')
implementation ('com.android.support:design:22.2.1')
implementation 'com.github.frankiesardo:linearlistview:1.0.1@aar'
}
这是我到目前为止尝试过的方法:
- 将以下内容添加到我的模块 build.gradle 文件的 android 部分:
sourceSets {
main{
java{
exclude '**/META-INF/MANIFEST'
exclude '**/META-INF/MANIFEST.MF'
exclude 'META-INF/MANIFEST'
exclude 'META-INF/MANIFEST.MF'
exclude '!META-INF/MANIFEST.MF'
}
}
}
- 添加这个:
sourceSets.main.res.filter.exclude 'META-INF/MANIFEST'
sourceSets.main.res.filter.exclude 'META-INF/MANIFEST.MF'
- 还有这个:
packagingOptions {
apply plugin: 'project-report'
exclude '**/META-INF/MANIFEST'
exclude '**/META-INF/MANIFEST.MF'
exclude 'META-INF/MANIFEST'
exclude 'META-INF/MANIFEST.MF'
exclude '!META-INF/MANIFEST.MF'
}
- 还有这个:
packagingOptions {
pickFirst '**/META-INF/MANIFEST'
pickFirst '**/META-INF/MANIFEST.MF'
pickFirst 'META-INF/MANIFEST'
pickFirst 'META-INF/MANIFEST.MF'
pickFirst '!META-INF/MANIFEST.MF'
}
- 这个:
aaptOptions {
ignoreAssetsPattern "!META-INF/MANIFEST.MF"
ignoreAssetsPattern "META-INF/MANIFEST.MF"
}
我想我已经尝试了几乎所有关于这个问题的方法:
How to exclude certain files from Android Studio gradle builds?
没有任何效果。
在搜索解决方案后,我认为问题是我有重复的依赖项。所以我尝试了以下方法:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation ('com.android.support:appcompat-v7:22.2.1'){
exclude module: 'support-v4'
}
implementation ('com.android.support:design:22.2.1')
implementation 'com.github.frankiesardo:linearlistview:1.0.1@aar'
}
还有这个:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation ('com.android.support:design:22.2.1'){
exclude module: 'support-v7'
}
implementation 'com.github.frankiesardo:linearlistview:1.0.1@aar'
}
我仍然遇到同样的错误。
我做错了什么?
正如Rajen Raiyarela所说,转到文件->项目结构->项目->Android Gradle 插件版本并将其从 3.5.2 降级到 3.5.1。
此问题是由于重复的依赖关系而发生的。
检查 Gradle 应用程序中的多个依赖项。
将项目依赖项设置为:
classpath 'com.android.tools.build:gradle:3.5.3'
或最新的。
注意:这样我的问题就解决了。
要么打包一次,要么不打包:
android {
packagingOptions {
pickFirst "META-INF/MANIFEST.MF"
// exclude "META-INF/MANIFEST.MF"
}
}
正如@rubo77
所说,在我确认后:
- 最新解决方案
- 升级gradle版本
- 例如:
- 从
3.5.2
到 3.5.3
- 从
3.5.2
到 3.5.4
- 已过时解决方案:
- 从
3.5.2
降级到 3.5.1
我的选择是:从 3.5.2
升级到 3.5.4
build.gradle
:
dependencies {
// classpath 'com.android.tools.build:gradle:3.5.2'
// classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:3.5.4'
}
我已经克隆了一个 github 存储库,因为我想研究代码,但是当我尝试在 Android Studio 中构建它时,我 运行 遇到了一些麻烦。 添加 google maven 存储库(由 Android Studio 提示)并更新 Gradle 插件版本和成绩版本(分别为 3.5.2 和 5.4.1)后,由于以下错误,构建失败:
Cause: duplicate entry: META-INF/MANIFEST.MF
这个,更具体地说:
Caused by: java.util.zip.ZipException: duplicate entry: META-INF/MANIFEST.MF
这是我的项目级别build.gradle文件:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}
}
这是我的模块 build.gradle 文件(在尝试之前):
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.thelittlenaruto.supportdesignexample"
minSdkVersion 11
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation ('com.android.support:appcompat-v7:22.2.1')
implementation ('com.android.support:design:22.2.1')
implementation 'com.github.frankiesardo:linearlistview:1.0.1@aar'
}
这是我到目前为止尝试过的方法:
- 将以下内容添加到我的模块 build.gradle 文件的 android 部分:
sourceSets {
main{
java{
exclude '**/META-INF/MANIFEST'
exclude '**/META-INF/MANIFEST.MF'
exclude 'META-INF/MANIFEST'
exclude 'META-INF/MANIFEST.MF'
exclude '!META-INF/MANIFEST.MF'
}
}
}
- 添加这个:
sourceSets.main.res.filter.exclude 'META-INF/MANIFEST'
sourceSets.main.res.filter.exclude 'META-INF/MANIFEST.MF'
- 还有这个:
packagingOptions {
apply plugin: 'project-report'
exclude '**/META-INF/MANIFEST'
exclude '**/META-INF/MANIFEST.MF'
exclude 'META-INF/MANIFEST'
exclude 'META-INF/MANIFEST.MF'
exclude '!META-INF/MANIFEST.MF'
}
- 还有这个:
packagingOptions {
pickFirst '**/META-INF/MANIFEST'
pickFirst '**/META-INF/MANIFEST.MF'
pickFirst 'META-INF/MANIFEST'
pickFirst 'META-INF/MANIFEST.MF'
pickFirst '!META-INF/MANIFEST.MF'
}
- 这个:
aaptOptions {
ignoreAssetsPattern "!META-INF/MANIFEST.MF"
ignoreAssetsPattern "META-INF/MANIFEST.MF"
}
我想我已经尝试了几乎所有关于这个问题的方法: How to exclude certain files from Android Studio gradle builds?
没有任何效果。
在搜索解决方案后,我认为问题是我有重复的依赖项。所以我尝试了以下方法:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation ('com.android.support:appcompat-v7:22.2.1'){
exclude module: 'support-v4'
}
implementation ('com.android.support:design:22.2.1')
implementation 'com.github.frankiesardo:linearlistview:1.0.1@aar'
}
还有这个:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation ('com.android.support:design:22.2.1'){
exclude module: 'support-v7'
}
implementation 'com.github.frankiesardo:linearlistview:1.0.1@aar'
}
我仍然遇到同样的错误。
我做错了什么?
正如Rajen Raiyarela所说,转到文件->项目结构->项目->Android Gradle 插件版本并将其从 3.5.2 降级到 3.5.1。
此问题是由于重复的依赖关系而发生的。
检查 Gradle 应用程序中的多个依赖项。
将项目依赖项设置为:
classpath 'com.android.tools.build:gradle:3.5.3'
或最新的。
注意:这样我的问题就解决了。
要么打包一次,要么不打包:
android {
packagingOptions {
pickFirst "META-INF/MANIFEST.MF"
// exclude "META-INF/MANIFEST.MF"
}
}
正如@rubo77
所说,在我确认后:
- 最新解决方案
- 升级gradle版本
- 例如:
- 从
3.5.2
到3.5.3
- 从
3.5.2
到3.5.4
- 从
- 例如:
- 升级gradle版本
- 已过时解决方案:
- 从
3.5.2
降级到3.5.1
- 从
我的选择是:从 3.5.2
升级到 3.5.4
build.gradle
:
dependencies {
// classpath 'com.android.tools.build:gradle:3.5.2'
// classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:3.5.4'
}