gpt4 book ai didi

android - Android-在gradle中如何排除依赖项中的某些资源文件?

转载 作者:行者123 更新时间:2023-12-03 04:00:32 25 4
gpt4 key购买 nike

我已经检查了很多关于stackoverflow的帖子,到目前为止,它们都没有起作用。因此,我有一个依赖于一系列AAR的APK,其中一个AAR有10个我不需要的音频文件。由于无法直接删除依赖项,因为我需要一些API,因此我想确保这些音频文件不会内置到APK中。

我检查音频文件是否内置的方法是运行以下命令:zipinfo MyApk.apk | grep .mp3
有谁知道如何从依赖项AAR中排除这些音频文件?

最佳答案

这就是我过去在AAR中排除一些文件的原因:

final List<String> exclusions = [];
Dependency.metaClass.exclude = { String[] currentExclusions ->
currentExclusions.each {
exclusions.add("${getGroup()}/${getName()}/${getVersion()}/${it}")
}
return thisObject
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile ('com.android.support:appcompat-v7:20.+')
debugCompile ('com.squareup.leakcanary:leakcanary-android:1.3.1')
.exclude("res/values-v21/values-v21.xml")
releaseCompile ('com.squareup.leakcanary:leakcanary-android-no-op:1.3.1')
}

tasks.create("excludeTask") << {
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
}
})

您可以检查此 Original Answer here

关于android - Android-在gradle中如何排除依赖项中的某些资源文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45227018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com