FileNotFoundException: Temp\...\launcher.aab does not exist

项目场景:

Unity导出AAB文件错误。

问题描述:

错误信息如下:

FileNotFoundException: Temp\gradleOut\launcher\build\outputs\bundle\release\launcher.aab does not exist
System.IO.File.Move (System.String sourceFileName, System.String destFileName) (at <9577ac7a62ef43179789031239ba8798>:0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <a5ce51c3ac7942f89b38f5afb48efa1b>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <a5ce51c3ac7942f89b38f5afb48efa1b>:0)
UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <a5ce51c3ac7942f89b38f5afb48efa1b>:0)
UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <a5ce51c3ac7942f89b38f5afb48efa1b>:0)
UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <599cc8297d774c7eab3d57de775dc8cb>:0)
UnityEditor.BuildPipeline:BuildPlayer(BuildPlayerOptions)
Google.Android.AppBundle.Editor.Internal.BuildTools.AndroidBuilder:Build(BuildPlayerOptions) (at Assets/ThirdParty/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/BuildTools/AndroidBuilder.cs:108)
Google.Android.AppBundle.Editor.Internal.BuildTools.AppBundleBuilder:BuildAndroidPlayer(BuildPlayerOptions) (at Assets/ThirdParty/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/BuildTools/AppBundleBuilder.cs:172)
Google.Android.AppBundle.Editor.Internal.AppBundlePublisher:Build(AppBundleBuilder, BuildPlayerOptions, AssetPackConfig, AppBundleBuildSettings) (at Assets/ThirdParty/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/AppBundlePublisher.cs:153)
Google.Android.AppBundle.Editor.Internal.AppBundlePublisher:Build() (at Assets/ThirdParty/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/AppBundlePublisher.cs:97)
Google.Android.AppBundle.Editor.Internal.AppBundleEditorMenu:BuildAndroidAppBundle() (at Assets/ThirdParty/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/AppBundleEditorMenu.cs:66)

原因分析:

gradle版本过高,导致与unity内部逻辑不兼容。

解决方案:

由于降低gradle版本可能引起一些列其他问题,所以不建议降低gradle版本;

Totally agree, unity should pay attention to this issue.
It is so easy to reproduce:

  1. unity 2019.4.17 + external gradle-6.7.1
  2. add classpath ‘com.android.tools.build:gradle:3.6.0’ to dependencies
  3. try to build aab
    Result: FileNotFoundException launcher.aab does not exist

Workaround: drop this to the bottom of your custom launcherTemplate.gradle

将下面这段代码贴到自定义 launcherTemplate.gradle 的底部

tasks.whenTaskAdded {
    
     task ->
    if (task.name.startsWith("bundle")) {
    
    
        def renameTaskName = "rename${task.name.capitalize()}Aab"
        def flavor = task.name.substring("bundle".length()).uncapitalize()
        tasks.create(renameTaskName, Copy) {
    
    
            def path = "${buildDir}/outputs/bundle/${flavor}/"
            from(path)
            include "launcher-release.aab"
            destinationDir file("${buildDir}/outputs/bundle/${flavor}/")
            rename "launcher-release.aab", "launcher.aab"
        }
 
        task.finalizedBy(renameTaskName)
    }
}

this code should rename your launcher-release.aab to launcher.aab
praise David Medenjak from

猜你喜欢

转载自blog.csdn.net/xiezi5160/article/details/115764304