...\bundle\release\launcher.aab does not exist 2019.4.16f1

FileNotFoundException: Temp\gradleOut\launcher\build\outputs\bundle\release\launcher.aab does not exist

When trying to update Gradle to version 3.6.0+, I came across the fact that the file that comes out has a different name than the unit expects.

In the folder I see the file: launcher-release.aab

How can I remove “-release” from the name? Or give Unity a new filename?

My launcherTemplate.gradle:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        // Must be Android Gradle Plugin 3.6.0 or later. For a list of
        // compatible Gradle versions refer to:
        // https://developer.android.com/studio/releases/gradle-plugin
        classpath 'com.android.tools.build:gradle:3.6.0'
    }
}

allprojects {
   repositories {
      google()
      jcenter()
      flatDir {
        dirs 'libs'
      }
   }
}



apply plugin: 'com.android.application'

dependencies {
    implementation project(':unityLibrary')
    }

android {
    compileSdkVersion **APIVERSION**
    buildToolsVersion '**BUILDTOOLS**'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion **MINSDKVERSION**
        targetSdkVersion **TARGETSDKVERSION**
        applicationId '**APPLICATIONID**'
        ndk {
            abiFilters **ABIFILTERS**
        }
        versionCode **VERSIONCODE**
        versionName '**VERSIONNAME**'
    }

    aaptOptions {
        noCompress = ['.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS**]
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
    }**SIGN**

    lintOptions {
        abortOnError false
    }

    buildTypes {
        debug {
            minifyEnabled **MINIFY_DEBUG**
            useProguard **PROGUARD_DEBUG**
            proguardFiles getDefaultProguardFile('proguard-android.txt')**SIGNCONFIG**
            jniDebuggable true
        }
        release {
            minifyEnabled **MINIFY_RELEASE**
            useProguard **PROGUARD_RELEASE**
            proguardFiles getDefaultProguardFile('proguard-android.txt')**SIGNCONFIG**
        }
    }**PACKAGING_OPTIONS****SPLITS**
**BUILT_APK_LOCATION**
    bundle {
        language {
            enableSplit = false
        }
        density {
            enableSplit = false
        }
        abi {
            enableSplit = true
        }
    }
}**SPLITS_VERSION_CODE****LAUNCHER_SOURCE_BUILD_SETUP**

6641143--757948--release 2020-12-20 01.29.44.png

Same issue when build AAB android with options:

- Enable mainGradle
- Enable baseGradle
- Enable launcherGradle
- Use Gradle 3.6.0 / 5.6.4

It is building success complete, but when Unity try to copy .aar file, path is wrong.
It must be:

Temp\gradleOut\launcher\build\outputs\bundle\release\launcher-release.aab

Best unity support, however, as usual

1 Like

Bump! :slight_smile:
Having the same issue, we needed to update Gradle due to some plugins (Facebook…)
but now the build fails because of the different naming…

Managed to find a workaround:

#if UNITY_ANDROID
using UnityEditor.Build;
using UnityEditor.Build.Reporting;

public class TempGradleAndroidPreProcessBuild : IPreprocessBuildWithReport
{
    public int callbackOrder => 0;

    public void OnPreprocessBuild (BuildReport report)
    {
        TempGradleFileWatcher.Start();
    }
}
#endif
#if UNITY_ANDROID
using UnityEditor;
using UnityEditor.Callbacks;

public class TempGradleAndroidPostProcessBuild
{
    [PostProcessBuild(0)]
    public static void ChangeGradleLauncherName (BuildTarget buildTarget, string pathToBuiltProject)
    {
        TempGradleFileWatcher.Stop();
    }
}
#endif
using System.IO;
using UnityEngine;

public static class TempGradleFileWatcher
{
    const string OLD_NAME = "launcher-release.aab";
    const string NEW_NAME = "launcher.aab";

    static string fileName;
    static string newFileName;
    static FileSystemWatcher watcher;

    public static void Start ()
    {
        string tempPath = Path.Combine(
            Application.dataPath,
            "..",
            "Temp",
            "gradleOut",
            "launcher",
            "build",
            "outputs",
            "bundle",
            "release"
        );
        fileName = Path.Combine(tempPath, OLD_NAME);
        newFileName = Path.Combine(tempPath, NEW_NAME);

        watcher = new FileSystemWatcher
        {
            Path = tempPath,
            NotifyFilter = NotifyFilters.LastAccess
            | NotifyFilters.LastWrite
            | NotifyFilters.FileName
            | NotifyFilters.DirectoryName,
            Filter = OLD_NAME,
            EnableRaisingEvents = true
        };
        watcher.Created += OnCreated;
    }

    public static void Stop ()
    {
        if (watcher != null)
            watcher.Dispose();
    }

    static void OnCreated (object sender, FileSystemEventArgs e) =>
        File.Move(fileName, newFileName);
}

It should start watching the Temp/gradleOut… folder when the build starts and change the file name to the expected one. Stops watching when the build ends.

This issue should be analyzed by the Unity team, because there doesn’t seem to be a proper way to modify this file through the build pipeline (please, correct me if I’m wrong). Tried using IPostGenerateGradleAndroidProject, but the changes were overridden.

2 Likes

Thanks for the code mvaz_p, i tried that fix but it didn’t work for me. However it gave me the idea to use a python script to do the same thing, and it worked!

Here’s the snippet for anyone interested, just put the file inside the project folder and execute it before building:

import os
import time

path = "Temp/gradleOut/launcher/build/outputs/bundle/release/launcher-release.aab"
pathNew = "Temp/gradleOut/launcher/build/outputs/bundle/release/launcher.aab"

print("Searching for file...")
while True:
   if os.path.isfile(path):
       try:
           os.rename(path, pathNew)
           print("FILE RENAMED!")
           break
       except Exception as e:
           pass
       else:
           pass
       finally:
           pass

   time.sleep(0.01)
2 Likes

Sup, guys.

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

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 android - How to change the generated filename for App Bundles with Gradle? - Stack Overflow

23 Likes

3.4.3

  • classpath ‘com.android.tools.build:gradle:3.4.3’ us this

had the same issue, removed file from Assets/Plugins/Android/baseProjectTemplate.gradle and issue has gone.

3 Likes

For anyone using older versions of Unity(which doesn’t have an option to create Custom launcherTemplate), just paste the code to mainTemplate, inside the bottom of defaultConfig. It also works for FileNotFoundException for gradleOut-release.aab too, just change every “launcher” to “gradleOut”.

2 Likes

Hi, I am working project on Unity version 2020.2.6f1. But when I build AAB for my project, the build gets failed & gets an Error Log.

Here is the Error log :
FileNotFoundException: Temp/gradleOut/launcher/build/outputs/bundle/release/launcher-release.aab does not exist.

Please Help to Resolve this problem.

2 Likes

Brilliant! A million thanks for this. Worked like a charm.

1 Like

I had the same error in working project on Unity version 2020.3.13f1.

This work out for me:

Open Assets/Plugins/Android/baseProjectTemplate.gradle

Change classpath ‘com.android.tools.build:gradle:3.4.0’

to classpath ‘com.android.tools.build:gradle:3.6.0’

2 Likes

Worked for me, many thanks!

Thanks pavel_luden!!!

I tweaked it slightly so it works for development builds too:

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-${flavor}.aab"
            destinationDir file("${buildDir}/outputs/bundle/${flavor}/")
            rename "launcher-${flavor}.aab", "launcher.aab"
        }
        task.finalizedBy(renameTaskName)
    }
}
4 Likes

Wow I go the Solution!!
Just add the following files in Plugin Folder
https://drive.google.com/drive/folders/1Fbosfmgn4f-bwWgkFAmOZPYjMOrDfsL5?usp=sharing

lol for me too, i thought was troll coment, but worked to mee haha thank =)

the code will be like this after edit ??

apply plugin: ‘com.android.application’

dependencies {
implementation project(‘:unityLibrary’)
}

android {
compileSdkVersion APIVERSION
buildToolsVersion ‘BUILDTOOLS

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion MINSDKVERSION
targetSdkVersion TARGETSDKVERSION
applicationId ‘APPLICATIONID
ndk {
abiFilters ABIFILTERS
}
versionCode VERSIONCODE
versionName ‘VERSIONNAME
}

aaptOptions {
noCompress = [‘.ress’, ‘.resource’, ‘.obb’] + unityStreamingAssets.tokenize(', ')
ignoreAssetsPattern = “!.svn:!.git:!.ds_store:!.scc:.:!CVS:!thumbs.db:!picasa.ini:!*~”
}SIGN

lintOptions {
abortOnError false
}

buildTypes {
debug {
minifyEnabled MINIFY_DEBUG
proguardFiles getDefaultProguardFile(‘proguard-android.txt’)SIGNCONFIG
jniDebuggable true
}
release {
minifyEnabled MINIFY_RELEASE
proguardFiles getDefaultProguardFile(‘proguard-android.txt’)SIGNCONFIG
}
}PACKAGING_OPTIONSPLAY_ASSET_PACKSSPLITS
BUILT_APK_LOCATION
bundle {
language {
enableSplit = false
}
density {
enableSplit = false
}
abi {
enableSplit = true
}
}

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)
}
}

}SPLITS_VERSION_CODE****LAUNCHER_SOURCE_BUILD_SETUP

where i must write this code ? can you explain more how to add it and where