android studio ignore assets pattern,Gradle duplicate entry error: META-INF/MANIFEST.MF (Or how to d...

在尝试构建从GitHub克隆的Android项目时,遇到了由于duplicate entry: META-INF/MANIFEST.MF错误导致的构建失败问题。已经尝试过更新Gradle版本、排除依赖、配置packagingOptions等方法,但问题依然存在。有人建议将Android Gradle Plugin Version降级或升级到特定版本,如3.5.3,以解决此问题。
摘要由CSDN通过智能技术生成

I've cloned a github repository because I wanted to study the code, but when I tried to build it in Android Studio, I ran into some trouble.

After adding the google maven repository (as prompted by Android Studio) and updating both the Gradle Plugin Version and the Grade Version (to 3.5.2 and to 5.4.1, respectively), the build fails because of the following error:

Cause: duplicate entry: META-INF/MANIFEST.MF

And this, to be more specific:

Caused by: java.util.zip.ZipException: duplicate entry: META-INF/MANIFEST.MF

Here is my project level build.gradle file:

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'

}

}

}

Here's my module build.gradle file (before trying anything):

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'

}

Here's what I've tried so far:

Adding the following to the android section of my module build.gradle file:

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'

}

}

}

Adding this:

sourceSets.main.res.filter.exclude 'META-INF/MANIFEST'

sourceSets.main.res.filter.exclude 'META-INF/MANIFEST.MF'

Also this:

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'

}

And this:

packagingOptions {

pickFirst '**/META-INF/MANIFEST'

pickFirst '**/META-INF/MANIFEST.MF'

pickFirst 'META-INF/MANIFEST'

pickFirst 'META-INF/MANIFEST.MF'

pickFirst '!META-INF/MANIFEST.MF'

}

This:

aaptOptions {

ignoreAssetsPattern "!META-INF/MANIFEST.MF"

ignoreAssetsPattern "META-INF/MANIFEST.MF"

}

Nothing worked.

After searching for a solution, I think the problem is that I have duplicated dependencies. So I've tried the following:

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'

}

And this:

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'

}

I still get the same error.

Could anyone please tell me what I'm doing wrong?

Thank you in anticipation. :)

# Answer 1

4d350fd91e33782268f371d7edaa8a76.png

As Rajen Raiyarela said, go to File->Project Structure->Project->Android Gradle Plugin Version and downgrade it from 3.5.2 to 3.5.1.

# Answer 2

Set project dependencies to:

classpath 'com.android.tools.build:gradle:3.5.3'

or latest one.

Note: by doing this, my problem has been resolved.

# Answer 3

This issue is happening because of duplicate dependencies.

Check for multiple dependencies in the Gradle app.

# Answer 4

Either package it once or not at all:

android {

packagingOptions {

pickFirst "META-INF/MANIFEST.MF"

// exclude "META-INF/MANIFEST.MF"

}

}

# Answer 5

as @rubo77 says and after my confirmation:

Latest solution

Upgrade gradle version

eg:

from 3.5.2 to 3.5.3

from 3.5.2 to 3.5.4

Obsolete solution:

downgrade from 3.5.2 to 3.5.1

my choice is : upgrade from 3.5.2 to 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'

}

fuBP6.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值