升级到 AGP7+,适配 assets 目录了吗

在这里插入图片描述

我们知道 assets 文件处理的任务是 merge[变体名称]ReleaseAssets,例如:

  • mergeCommonReleaseAssets
  • mergeReleaseAssets
  • mergeDebugAssets

在 AGP 升级过程中,不同的 Android Gradle Plugin 版本打包过程中处理 assets 文件的临时目录可能存在不一致的情况!

在 AGP4+

assets 文件合并的临时目录是在

build/intermediates/merged_assets/commonRelease/out

在这里插入图片描述

在 AGP7.2.0

assets 文件合并的临时目录是在

build/intermediates/assets/release/mergeReleaseAssets

在这里插入图片描述

在 AGP7.4.1

assets 文件合并的临时目录是在

build/intermediates/assets/commonRelease

在这里插入图片描述

路径适配

AGP 升级路径适配是一个要点,当前还没升级测试 AGP8+,可能在路径上也有所变化,实测才能知道。

// AGP4+
// build/intermediates/merged_assets/commonRelease/out
String folderPath = PluginFileUtils.adjustPath(mProject.projectDir.path,
        FileConstant.FILE_DIR_BUILD,
        FileConstant.FILE_DIR_INTERMEDIATES,
        FileConstant.FILE_DIR_MERGED_ASSETS,
        CommUtils.getFirstCharLowercaseStr(CommonManager.getmVariantName()),
        FileConstant.FILE_DIR_OUT)

// AGP7.2.0
// build/intermediates/assets/release/mergeReleaseAssets
String subDirname = "merge" + CommonManager.getmBuildType().capitalize() + "Assets"
String folderPath2 = PluginFileUtils.adjustPath(mProject.projectDir.path,
        FileConstant.FILE_DIR_BUILD,
        FileConstant.FILE_DIR_INTERMEDIATES,
        FileConstant.FILE_DIR_MERGED_ASSETS,
        CommonManager.getmBuildType().toLowerCase(),
        subDirname)
        
// AGP7.4.1
// build/intermediates/assets/commonRelease
String folderPath = PluginFileUtils.adjustPath(mProject.projectDir.path,
        FileConstant.FILE_DIR_BUILD,
        FileConstant.FILE_DIR_INTERMEDIATES,
        FileConstant.FILE_DIR_MERGED_ASSETS,
        CommUtils.getFirstCharLowercaseStr(CommonManager.getmVariantName()))

通常我们在某个 Task 前后插入处理任务以满足需求。

mProject.afterEvaluate {
	Iterator<Task> eIterator = mProject.tasks.findAll().iterator()
	switch (CommUtils.judgeTaskType(theTask.name)) {
	 case TaskType.TASK_MERGE_RELEASE_ASSETS:
		theTask.doLast {
    		processMergeReleaseAssets()
		}
		break
	}
}
flutter安装image_gallery_saver后运行报错,怎么解决 FAILURE: Build completed with 2 failures. 1: Task failed with an exception. ----------- * What went wrong: A problem occurred configuring project ':image_gallery_saver'. > Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl. > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace. If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant. * 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. ============================================================================== 2: Task failed with an exception. ----------- * What went wrong: Failed to query the value of property 'buildFlowServiceProperty'. > Could not isolate value org.jetbrains.kotlin.gradle.plugin.statistics.BuildFlowService$Parameters_Decorated@4e390559 of type BuildFlowService.Parameters > A problem occurred configuring project ':image_gallery_saver'. > Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl. > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace. If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant. * 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. ============================================================================== BUILD FAILED in 1s Running Gradle task 'assembleDebug'... 2,434ms Error: Gradle task assembleDebug failed with exit code 1 PS D:\develop\Flutter\ProjectTest\words_myths> flutter run Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source! Launching lib\main.dart on M2007J22C in debug mode... Support for Android x86 targets will be removed in the next stable release after 3.27. See https://github.com/flutter/flutter/issues/157543 for details. FAILURE: Build completed with 2 failures. 1: Task failed with an exception. ----------- * What went wrong: A problem occurred configuring project ':image_gallery_saver'. > Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl. > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace. If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant. * 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. ============================================================================== 2: Task failed with an exception. ----------- * What went wrong: Failed to query the value of property 'buildFlowServiceProperty'. > Could not isolate value org.jetbrains.kotlin.gradle.plugin.statistics.BuildFlowService$Parameters_Decorated@312973b2 of type BuildFlowService.Parameters > A problem occurred configuring project ':image_gallery_saver'. > Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl. > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace. If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant. * 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. ============================================================================== BUILD FAILED in 1s Running Gradle task 'assembleDebug'... 2,546ms Error: Gradle task assembleDebug failed with exit code 1 PS D:\develop\Flutter\ProjectTest\words_myths>
06-22
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值