gpt4 book ai didi

android - Gradle 应用程序变体 mergeAssets 不工作

转载 作者:行者123 更新时间:2023-11-29 01:40:57 24 4
gpt4 key购买 nike

我正在尝试使用 gradle applicationVariants mergeAssets 任务从我的 apk 中删除一些未使用的 Assets 文件。

即使我能够打印“this line is printed”行,当应用程序变体“运行”时,variant.mergeAssets.doFirst {} 似乎没有被调用,因为我从未在我的 gradle 控制台中看到输出“此行未打印”。我尝试删除的 Assets 也没有被删除,但似乎从未执行过删除它的代码。

我做错了什么吗?我试过将整个 android.applicationVariants 任务移到 buildTypes 之外,我试过将它嵌套在 release{} 中。我什么都没有试过似乎有效。

buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), file('proguard-project.txt')
signingConfig signingConfigs.release
}

publicBeta.initWith(buildTypes.release)
publicBeta {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), file('proguard-project.txt')
}

android.applicationVariants.all { variant ->
println 'this line is printed'
variant.mergeAssets.doFirst {
println 'this line is never printed'
File fonts = file("${rootDir}/build/intermediates/exploded-aar/com.github.johnkil.android-robototextview/robototextview/2.0.1/assets/fonts")
if (fonts.exists()) {
for (File file : fonts.listFiles()) {
if (file.getName().contains("RobotoSlab")) {
println("delete " + file.getName() + " font")
file.delete()
};
}
}
}
}
}

为简洁起见,这里是 gradle 控制台输出:

Executing tasks: [:shuttle_paid:assembleRelease]

Configuration on demand is an incubating feature.
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
this line is printed
this line is printed
this line is printed
:shuttle_library:compileLint
:shuttle_library:copyReleaseLint UP-TO-DATE
:shuttle_library:preBuild
:shuttle_library:preReleaseBuild
:shuttle_library:checkReleaseManifest
:shuttle_library:preDebugBuild
:shuttle_library:preDebugTestBuild
:libraries:castcompanionlibrary-android:compileLint
:libraries:castcompanionlibrary-android:copyReleaseLint UP-TO-DATE
:libraries:castcompanionlibrary-android:preBuild
:libraries:castcompanionlibrary-android:preReleaseBuild
:libraries:castcompanionlibrary-android:checkReleaseManifest
:libraries:castcompanionlibrary-android:preDebugBuild
:libraries:castcompanionlibrary-android:preDebugTestBuild
:libraries:castcompanionlibrary-android:prepareComAndroidSupportAppcompatV72000Library UP-TO-DATE
:libraries:castcompanionlibrary-android:prepareComAndroidSupportMediarouterV72000Library UP-TO-DATE
:libraries:castcompanionlibrary-android:prepareComAndroidSupportSupportV42000Library UP-TO-DATE
:libraries:castcompanionlibrary-android:prepareComGoogleAndroidGmsPlayServices5077Library UP-TO-DATE
:libraries:castcompanionlibrary-android:prepareReleaseDependencies
:libraries:castcompanionlibrary-android:compileReleaseAidl UP-TO-DATE
:libraries:castcompanionlibrary-android:compileReleaseRenderscript UP-TO-DATE
:libraries:castcompanionlibrary-android:generateReleaseBuildConfig UP-TO-DATE
:libraries:castcompanionlibrary-android:generateReleaseAssets UP-TO-DATE
:libraries:castcompanionlibrary-android:mergeReleaseAssets UP-TO-DATE
:libraries:castcompanionlibrary-android:generateReleaseResValues UP-TO-DATE
:libraries:castcompanionlibrary-android:generateReleaseResources UP-TO-DATE
:libraries:castcompanionlibrary-android:mergeReleaseResources UP-TO-DATE
:libraries:castcompanionlibrary-android:processReleaseManifest UP-TO-DATE
:libraries:castcompanionlibrary-android:processReleaseResources UP-TO-DATE
:libraries:castcompanionlibrary-android:generateReleaseSources UP-TO-DATE
:libraries:castcompanionlibrary-android:compileReleaseJava UP-TO-DATE
:libraries:castcompanionlibrary-android:extractReleaseAnnotations UP-TO-DATE
:libraries:castcompanionlibrary-android:mergeReleaseProguardFiles UP-TO-DATE
:libraries:castcompanionlibrary-android:processReleaseJavaRes UP-TO-DATE
:libraries:castcompanionlibrary-android:packageReleaseJar UP-TO-DATE
:libraries:castcompanionlibrary-android:compileReleaseNdk UP-TO-DATE
:libraries:castcompanionlibrary-android:packageReleaseJniLibs UP-TO-DATE
:libraries:castcompanionlibrary-android:packageReleaseLocalJar UP-TO-DATE
:libraries:castcompanionlibrary-android:packageReleaseRenderscript UP-TO-DATE
:libraries:castcompanionlibrary-android:packageReleaseResources UP-TO-DATE
:libraries:castcompanionlibrary-android:bundleRelease UP-TO-DATE
:shuttle_library:prepareComAndroidSupportAppcompatV72000Library UP-TO-DATE
:shuttle_library:prepareComAndroidSupportMediarouterV72000Library UP-TO-DATE
:shuttle_library:prepareComAndroidSupportSupportV42000Library UP-TO-DATE
:shuttle_library:prepareComGithubJohnkilAndroidRobototextviewRobototextview210Library UP-TO-DATE
:shuttle_library:prepareComGoogleAndroidGmsPlayServices5077Library UP-TO-DATE
:shuttle_library:prepareComLarswerkmanHoloColorPicker14Library UP-TO-DATE
:shuttle_library:prepareShuttleLibrariesCastcompanionlibraryAndroidUnspecifiedLibrary UP-TO-DATE
:shuttle_library:prepareReleaseDependencies
:shuttle_library:compileReleaseAidl UP-TO-DATE
:shuttle_library:compileReleaseRenderscript UP-TO-DATE
:shuttle_library:generateReleaseBuildConfig UP-TO-DATE
:shuttle_library:generateReleaseAssets UP-TO-DATE
:shuttle_library:mergeReleaseAssets UP-TO-DATE
:shuttle_library:generateReleaseResValues UP-TO-DATE
:shuttle_library:generateReleaseResources UP-TO-DATE
:shuttle_library:mergeReleaseResources UP-TO-DATE
:shuttle_library:processReleaseManifest UP-TO-DATE
:shuttle_library:processReleaseResources UP-TO-DATE
:shuttle_library:generateReleaseSources UP-TO-DATE
:shuttle_library:compileReleaseJava UP-TO-DATE
:shuttle_library:extractReleaseAnnotations UP-TO-DATE
:shuttle_library:mergeReleaseProguardFiles UP-TO-DATE
:shuttle_library:processReleaseJavaRes UP-TO-DATE
:shuttle_library:packageReleaseJar UP-TO-DATE
:shuttle_library:compileReleaseNdk UP-TO-DATE
:shuttle_library:packageReleaseJniLibs UP-TO-DATE
:shuttle_library:packageReleaseLocalJar UP-TO-DATE
:shuttle_library:packageReleaseRenderscript UP-TO-DATE
:shuttle_library:packageReleaseResources UP-TO-DATE
:shuttle_library:bundleRelease UP-TO-DATE
:shuttle_paid:preBuild
:shuttle_paid:preReleaseBuild
:shuttle_paid:checkReleaseManifest
:shuttle_paid:preDebugBuild
:shuttle_paid:prePublicBetaBuild
:shuttle_paid:prepareComAndroidSupportAppcompatV72000Library UP-TO-DATE
:shuttle_paid:prepareComAndroidSupportMediarouterV72000Library UP-TO-DATE
:shuttle_paid:prepareComAndroidSupportSupportV42000Library UP-TO-DATE
:shuttle_paid:prepareComGithubJohnkilAndroidRobototextviewRobototextview210Library UP-TO-DATE
:shuttle_paid:prepareComGoogleAndroidGmsPlayServices5077Library UP-TO-DATE
:shuttle_paid:prepareComLarswerkmanHoloColorPicker14Library UP-TO-DATE
:shuttle_paid:prepareShuttleLibrariesCastcompanionlibraryAndroidUnspecifiedLibrary UP-TO-DATE
:shuttle_paid:prepareShuttleShuttle_libraryUnspecifiedLibrary UP-TO-DATE
:shuttle_paid:prepareReleaseDependencies
:shuttle_paid:compileReleaseAidl UP-TO-DATE
:shuttle_paid:compileReleaseRenderscript UP-TO-DATE
:shuttle_paid:generateReleaseBuildConfig UP-TO-DATE
:shuttle_paid:generateReleaseAssets UP-TO-DATE
:shuttle_paid:mergeReleaseAssets UP-TO-DATE
:shuttle_paid:generateReleaseResValues UP-TO-DATE
:shuttle_paid:generateReleaseResources UP-TO-DATE
:shuttle_paid:mergeReleaseResources UP-TO-DATE
:shuttle_paid:processReleaseManifest UP-TO-DATE
:shuttle_paid:processReleaseResources UP-TO-DATE
:shuttle_paid:generateReleaseSources UP-TO-DATE
:shuttle_paid:compileReleaseJava UP-TO-DATE
:shuttle_paid:lintVitalRelease
:shuttle_paid:compileReleaseNdk UP-TO-DATE
:shuttle_paid:proguardRelease UP-TO-DATE
:shuttle_paid:dexRelease UP-TO-DATE
:shuttle_paid:processReleaseJavaRes UP-TO-DATE
:shuttle_paid:validateReleaseSigning
:shuttle_paid:packageRelease UP-TO-DATE
:shuttle_paid:zipalignRelease UP-TO-DATE
:shuttle_paid:assembleRelease

BUILD SUCCESSFUL

Total time: 8.682 secs

最佳答案

打印的行将始终被打印,因为它在配置阶段执行。 (参见 Gradle User Guide)

您的 gradle 控制台输出显示所有被跳过的 merge*Resources 任务都是最新的。这意味着自上次执行任务以来输入和输出没有改变,因此 gradle 不会再次执行它们。不幸的是,Gradle 还不够聪明,无法知道您已经更改了任务实现并且它不应该跳过任务。

尝试运行清理以强制运行任务

关于android - Gradle 应用程序变体 mergeAssets 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24719133/

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