Java Android gradle:从外部依赖项中排除文件
我添加了Java Android gradle:从外部依赖项中排除文件,java,android,kotlin,Java,Android,Kotlin,我添加了com.eftimoff:android路径视图:1.0。8@aar添加到我的项目中,但当我运行应用程序时,出现以下错误: 原因:重复条目:META-INF/MANIFEST.MF 这是外部库中的pathview文件: 现在我想排除META-INF文件夹,所以我将其添加到模块gradle中: android { ... packagingOptions { exclude 'META-INF/*' } } 但我还是犯了以上的错误 我写了格雷德尔的剧本
com.eftimoff:android路径视图:1.0。8@aar
添加到我的项目中,但当我运行应用程序时,出现以下错误:
原因:重复条目:META-INF/MANIFEST.MF
这是外部库中的pathview
文件:
现在我想排除META-INF
文件夹,所以我将其添加到模块gradle中:
android {
...
packagingOptions {
exclude 'META-INF/*'
}
}
但我还是犯了以上的错误
我写了格雷德尔的剧本
当我这样添加库时:
implementation('com.eftimoff:android路径视图: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
这就是您的问题是由多个问题引起的,这就是为什么它更难修复的原因。 首先,Gradle Android插件版本3.5.2似乎有一个错误,您无法从apk中删除这些额外的清单文件。 作为一种解决方法,您可以将插件恢复到版本
3.5.1
(不是Android Studio,恢复插件版本就足够了)
然后您看到了错误:
原因:重复条目:META-INF/MANIFEST.MF
这是因为您临时删除了该零件
packagingOptions {
exclude 'META-INF/MANIFEST.MF'
}
从你build.gradle,因为它没有工作,因为插件错误。
最后,您看到了错误:
在模块androidsvg-1.2.1.jar(android-pathview-1.0.8.aar)和androidsvg-1.2.1.jar(com.eftimoff:android-pathview:1.0.8)中找到重复的类com.caverock.androidsvg.CSSParser
这是因为您在
libs/
文件夹中包含了一个修改过的库,但忘记将其从implementation{}
部分中删除,所以它被包含了两次。这不起作用吗?packagingOptions{exclude'META-INF/MANIFEST.MF}请注意,我使用的路径开头没有前导/前导exclude'META-INF/MANIFEST.MF
但是我得到了原因:重复条目:META-INF/MANIFEST.MF
error@Danielzolnai您使用的是Gradle Android插件3.5.2吗?如果是,您可以尝试降级到3.5.1吗?(不是Studio,只是插件版本)是的,我正在使用gradle 3.5.2classpath'com.android.tools.build:gradle:3.5.2'
,还更新了我的帖子@Danielzolnai从你的libs/中删除android-pathview-1.0.8.aar,然后重试。
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
}
})
\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'
}