重复条目:构建.apk时输入META-INF/.与gradle插件3.0.0.排除此处不适用 [英] duplicate entry: META-INF/ when build .apk. with gradle plugin 3.0.0. Exclude not applicable here
问题描述
在问这个问题之前,我搜索了一个答案
Before asking this question I searched for an answer
简而言之:最新版本的Gradle插件(适用于Android Studio 3.0.0版)出现问题.
In short: problem appears with the latest version of Gradle plugin for Android Studio version 3.0.0.
如果我使用较早版本的Gradle插件(2.3.3),Studio会毫无问题地构建.apk/
If I use previous version of Gradle plugin (2.3.3) Studio builds .apk without problem/
错误文字:
错误:任务执行失败 ':stockManagment:transformClassesWithStackFramesFixerForNextDebug'.
Error:Execution failed for task ':stockManagment:transformClassesWithStackFramesFixerForNextDebug'.
com.android.build.api.transform.TransformException:java.lang.RuntimeException:java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.builder.utils.FileCache $ FileCreatorException: java.util.zip.ZipException:重复项:META-INF/
com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.builder.utils.FileCache$FileCreatorException: java.util.zip.ZipException: duplicate entry: META-INF/
在SO和其他站点上找到的所有解决方案都建议使用排除",但是这些问题通常出现在"META-INF/somefile.txt"而不是"META-INF/"目录本身中.
All solutions found at SO and other sites recommend using 'exclude', but these problems usually appear with 'META-INF/somefile.txt' , not 'META-INF/' directory itself.
我不能排除整个"META-INF/"目录,但要排除此目录中的常用文件(许可证,依赖项等).
I can't exclude whole 'META-INF/' directory, but I exclude common files inside this dir (licence, dependencies, etc.).
这是我的build.gradle文件.
Here are my build.gradle files.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
和
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.24.3'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
signingConfigs {
release_config {
keyAlias 'stock_managment'
keyPassword '********'
storeFile file('../stockmanagment_keystore.jks')
storePassword '********'
}
}
defaultConfig {
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
multiDexKeepProguard file('multidex-config.pro')
signingConfig signingConfigs.release_config
}
debug {
}
}
flavorDimensions "next"
productFlavors {
next {
applicationId "com.stockmanagment.next.app"
minSdkVersion 15
targetSdkVersion 25
multiDexEnabled true
versionCode 47
versionName '2.0.17'
dimension "next"
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
lintOptions {
abortOnError false
}
dexOptions {
javaMaxHeapSize "4g"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LGPL2.1'
}
}
def support = '26.1.0'
def dagger = '2.11'
def butterKnife = "8.8.1"
def moxy = "1.5.3"
def robolectric = "3.0"
dependencies {
implementation fileTree(include: ['*.jar'], dir: '../libs')
implementation('com.crashlytics.sdk.android:crashlytics:2.6.6@aar') {
transitive = true
}
implementation "com.google.dagger:dagger:$dagger"
implementation("com.android.support:recyclerview-v7:$support") {
exclude group: 'com.android.support', module: 'cardview-v7'
}
implementation("com.android.support:design:$support") {
exclude group: 'com.android.support', module: 'cardview-v7'
}
implementation("com.android.support:appcompat-v7:$support") {
exclude group: 'com.android.support', module: 'cardview-v7'
}
implementation("com.android.support:preference-v7:$support") {
exclude group: 'com.android.support', module: 'cardview-v7'
}
implementation "com.jakewharton:butterknife:$butterKnife"
implementation("com.android.support:support-v4:$support") {
exclude group: 'com.android.support', module: 'cardview-v7'
}
annotationProcessor "com.google.dagger:dagger-compiler:$dagger"
annotationProcessor "com.jakewharton:butterknife-compiler:$butterKnife"
implementation "com.arello-mobile:moxy:$moxy"
implementation "com.arello-mobile:moxy-app-compat:$moxy"
testImplementation "org.robolectric:robolectric:$robolectric"
testImplementation "org.robolectric:shadows-multidex:$robolectric"
annotationProcessor "com.arello-mobile:moxy-compiler:$moxy"
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'petrov.kristiyan.colorpicker:colorpicker-library:1.1.2'
implementation 'com.borax12.materialdaterangepicker:library:1.9'
implementation 'com.nineoldandroids:library:2.4.0'
implementation 'de.hdodenhof:circleimageview:2.1.0'
implementation 'io.reactivex.rxjava2:rxjava:2.1.2'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'com.android.support:multidex:1.0.2'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.4.7'
implementation 'com.nikhilpanju.recyclerviewenhanced:recyclerviewenhanced:1.1.0'
implementation 'com.github.johnkil.print:print:1.3.1'
implementation 'com.github.ybq:Android-SpinKit:1.1.0'
implementation 'com.github.tiromansev:Android-Prefs-Wrapper:0.2.2'
implementation 'org.solovyev.android:checkout:1.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'org.mockito:mockito-core:2.5.0'
implementation 'it.sephiroth.android.library.targettooltip:target-tooltip-library:1.3.15'
implementation 'com.github.arimorty:floatingsearchview:2.1.1'
implementation 'com.github.tiromansev:Android-Permission-Manager:0.2.7'
implementation 'com.itextpdf:itextpdf:5.5.12'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
implementation 'com.github.tiromansev:Android-File-Dialog:0.2.4'
implementation 'com.github.tiromansev:Android-Scan-Barcode:0.3.0'
implementation 'com.github.tiromansev:FloatingActionButton:1.6.7'
implementation 'com.github.tiromansev:AndroidTreeView:0.0.1'
}
task copyLocales << {
copy {
from 'src/main/res/values-ru/strings.xml'
into 'src/main/res/values-uk'
}
copy {
from 'src/main/res/values-ru/strings.xml'
into 'src/main/res/values-be'
}
copy {
from 'src/main/res/values/strings.xml'
into 'src/main/res/values-en'
}
}
preBuild.dependsOn copyLocales
tasks.whenTaskAdded { task ->
if (task.name == "lint") {
task.enabled = false
}
}
在此先感谢您的帮助.
推荐答案
问题出在Apache POI库中,该库以.jar文件的形式包含在/libs目录中. .jar包含空的/META-INF目录,这是问题的原因.
The problem was with Apache POI library which was included as .jar file from /libs directory. This .jar contained empty /META-INF directory which was the cause of the problem.
从.jar文件删除此空目录可解决此问题.如果/META-INF不为空,则也可以.使用Gradle插件2.3.3,即使在/META_INF目录为空的情况下,.apk仍可顺利运行.
Deleting this empty directory from .jar file resolved the problem. If /META-INF is not empty it also works ok. With Gradle plugin 2.3.3 building .apk works smoothly even with empty /META_INF directory.
因此,Gradle插件3.0.0和.jar中空的/META_INF目录的组合会造成问题.
So, the combination of Gradle plugin 3.0.0 and empty /META_INF directory in .jar creates the problem.
更新27.11.2017 该错误已在当前版本中修复
UPDATE 27.11.2017 This bug has been fixed in the current version
这篇关于重复条目:构建.apk时输入META-INF/.与gradle插件3.0.0.排除此处不适用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!