【问题标题】:How can I exclude/delete flavour specific asset files through Gradle?如何通过 Gradle 排除/删除特定于风味的资产文件?
【发布时间】:2020-06-18 23:03:45
【问题描述】:

在我的 React Native 应用程序中,我有两种风格。每种风味都有一些仅在该风味中使用的图像和视频资产。

为了减小 APK 的大小,我想在构建之前或构建期间排除不必要的资源。

最好的方法是什么?

我确实尝试使用 aaptOptions,如下所示,但这对我没有用:

aaptOptions {
        '/folder:*.jpg:*.png'
        ignoreAssetsPattern "!/"+projectName+":*.mp4:"
}

我之前在 build.gradle 文件的底部有以下任务:

task deleteOtherFlavourAssets(type: Delete) {
    description = 'Deleting non $projectName assets'
    delete fileTree("src").matching {
        exclude "**/app_assets_$projectName**"
        include "**/app_assets_**"
    }
}

preBuild.dependsOn deleteOtherFlavourAssets

这可以完成一段时间的工作,但是几个月前它就停止了工作。我无法让它再次工作。

我应该提一下,当将上述任务作为副本运行(而不是删除)时,正确的文件会复制到此目录中。

task otherFlavourAssets(type: Copy) {
    description = 'Copying non $projectName assets to temp directory'
    copy {
        from fileTree("src").matching {
            exclude "**/app_assets_$projectName**"
            include "**/app_assets_**"
        }
        into 'tempAssetStore'
    }
}

没有其他相关的自定义任务。所以很有可能后续的 React Native 构建任务正在复制/合并多余的资产,或者可能是缓存问题。

【问题讨论】:

    标签: android react-native gradle


    【解决方案1】:

    我不知道 Gradle 是否在这种情况下发生了变化,或者这是否可能是一个问题,但你的过滤器模式对我来说有点奇怪。 ** 通常用于描述零个或多个目录级别,我从未见过将** 与目录名称结合使用的模式。你可以试试下面的模式吗?

    task deleteOtherFlavourAssets(type: Delete) {
        description = 'Deleting non $projectName assets'
        delete fileTree("src").matching {
            exclude "**/app_assets_$projectName*/**"
            include "**/app_assets_*/**"
        }
    }
    

    【讨论】:

    • 谢谢,但我认为这不是问题所在。之前尝试过该过滤模式并刚刚再次运行它,APK 仍然包含两组图像和视频。尽管某些相关文件的路径有 7 层深,但在将该任务作为副本运行时,任一模式变体都会选择正确的文件。
    猜你喜欢
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 2014-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多