Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All asset bundles also in base_assets when using Unity 2021 #62

Closed
szeleneyr opened this issue Aug 19, 2022 · 9 comments
Closed

All asset bundles also in base_assets when using Unity 2021 #62

szeleneyr opened this issue Aug 19, 2022 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@szeleneyr
Copy link

szeleneyr commented Aug 19, 2022

We make use of this plugin for quite a while now which always worked flawlessly since Unity 2019. But after upgrading to Unity 2021.3.5f1 the final AAB is almost double size, after investigating it looks like all assets bundles are also part of base_asset (base_assets/assets/aa has all asset bundles too, which was not the case in earlier versions).

Is this maybe a known issue already? Does anyone have a hint where to look at? (maybe Unity 2021 is building the addressables again when building the player?)

We are using Addressables 1.19.19 and play-asset-delivery 1.7.0 (worked fine with Unity 2020)

@jelte
Copy link
Owner

jelte commented Aug 19, 2022

Yes, there is an issue with 2021 and addressables 1.19+, as in the combination of those, Addressables no longer copies bundles to StreamingAssets.

Not sure how to fix it yet, but I got some time off in 2 weeks, at which point I'll be taking a look at this.

@jelte jelte self-assigned this Aug 19, 2022
@jelte jelte added the bug Something isn't working label Aug 19, 2022
@szeleneyr
Copy link
Author

szeleneyr commented Aug 19, 2022

Thanks you for the update. I mean, they work fine, they build correctly, upload correctly and can be loaded/addressed without any issue. The problem is "just" that the base/base_assets bundle also contains all the asset bundles.

If you take a look at the delivery section in play console you will see that the base_assets bundle is the size of base.bundle and all other asset bundles.

While building, I saw that at one point in the process the com.unity.addressables/assets/android folder is cleaned while building the player with Unity 2020, but it is not cleaned when building with 2021, maybe thats the reason? (even once the build is done all bundles are still in this folder)

Anyway, thanks for taking a look at this, let me know if you need someone to debug and test early, I will be around!

Addressables 1.19.19
Unity 2021.3.5f1
com.google.android.appbundle@1.7.0
com.google.play.assetdelivery@1.7.0
com.google.play.common@1.7.0
com.google.play.core@1.7.0

Our usual build procedure:

...
AddressableAssetSettings.CleanPlayerContent( );
BuildCache.PurgeCache(false);
AddressableAssetSettings.BuildPlayerContent();
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();

buildResult = Khepri.PlayAssetDelivery.Editor.AssetPackBuilder.BuildBundleWithAssetPacks(buildPlayerOptions, EditorUserBuildSettings.androidBuildSubtarget);
...

@szeleneyr
Copy link
Author

Did you have any chance looking at this issue already? Any way I can be of help here?

@szeleneyr
Copy link
Author

szeleneyr commented Oct 4, 2022

Investigated this issue a bit and it looks like we can get back to normal AAB size by manually removing the duplicate bundles from the base bundle when building (very hacky, but at least working for now with Unity 2021.3.11f1, addressables 1.19.19 and app bundle 1.7.0)

private static void ArrangeFilesForExistingModule(DirectoryInfo source, DirectoryInfo destination)
{
    // Only include the resources.pb file located directly in the source directory.
    foreach (var sourceFileInfo in source.GetFiles())
    {
        if (sourceFileInfo.Name == ResourceTableFileName)
        {
            sourceFileInfo.MoveTo(Path.Combine(destination.FullName, ResourceTableFileName));
        }
    }

    // Include all directories located in the source directory.
    foreach (var sourceDirectoryInfo in source.GetDirectories())
    {
	    sourceDirectoryInfo.MoveTo(Path.Combine(destination.FullName, sourceDirectoryInfo.Name));
        
	    // ADDED
	    CleanupDuplicateBundlesStillInBaseModule(sourceDirectoryInfo, destination);

    }
}

// ADDED
private static void CleanupDuplicateBundlesStillInBaseModule(DirectoryInfo sourceDirectoryInfo, DirectoryInfo destination)
{
if (sourceDirectoryInfo.Name.Contains("assets"))
{
	DirectoryInfo di = new DirectoryInfo(Path.Combine(destination.FullName, sourceDirectoryInfo.Name, "aa"));
	var files = di.GetFiles();

	foreach (FileInfo file in files)
	{
		if (file.Extension == ".bundle" && !file.Name.Contains("unitybuiltinshaders") && !file.Name.Contains("packedassets") && !file.Name.Contains("catalog"))
			file.Delete();
	}
}
}

@jelte
Copy link
Owner

jelte commented Oct 4, 2022

Sorry, I've been extremely busy with work lately and had little time.

I had a quick look, but I haven't had time to verify the fix.

so I thought it is as simple as changing:

PlayAssetPackBundlesPreprocessor.cs line 22 to use the BuildPath instead of PlayerBuildDataPath

var bundles = AssetPackBuilder.GetBundles(Addressables.BuildPath, SearchOption.AllDirectories);

But Unity changed how android is being build, and adds things to a manifest list, which isn't accessable, so I need to hack around that..., thank you Unity...

@jelte
Copy link
Owner

jelte commented Oct 4, 2022

Ok think I resolved it, a less hacky way then what you suggested.

Basically by removing the bundle slightly earlier in the process than in Unity 2020.

I've created a new release 1.0.1.

@jelte jelte closed this as completed Oct 4, 2022
@szeleneyr
Copy link
Author

szeleneyr commented Oct 5, 2022

Less hacky is always preferred :) Will try your changes...

@szeleneyr
Copy link
Author

szeleneyr commented Oct 5, 2022

Unfortunately your fix didn't solve the issue, actually got worse

  • I have still all addressables asset bundles duplicated in base/assets/aa or base_assets/assets/aa
  • The base module (if SplitBaseModule is disabled) doesn't contain the ManageData folder anymore which makes the app crash

@lvgrecords
Copy link

Unfortunately your fix didn't solve the issue, actually got worse

  • I have still all addressables asset bundles duplicated in base/assets/aa or base_assets/assets/aa
  • The base module (if SplitBaseModule is disabled) doesn't contain the ManageData folder anymore which makes the app crash

same for me :(

kreys pushed a commit to kreys/be.khepri.play.assetdelivery.addressables that referenced this issue Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants