Hello, currently I am implementing PAD to reduce the app size for google store.
In Addressables I created groups from the PAD template with Play Asset Delivery scheme and Content Packing and Loading scheme.
I noticed that with this my “base” module plus install-time build size still remains the same, but the dialog just added new section with on-demand packs. Which leads me to believe that assets might be wrongly packed and are still included in the base module.
In the end the real issue is that after my app starts it crashes with null ref while trying to download the asset packs.
PID: [5408] AssetPackServiceImpl : getPackStates([RomeAssetPack, JapanAssetPack])
PID: [5408] AssetPackServiceImpl : Initiate binding to the service.
5408 18611 Error Unity NullReferenceException: Object reference not set to an instance of an object.
5408 18611 Error Unity at AssetPacksManager.DownloadAllPacks () [0x00000]
It fails directly on this line of code in my script:
stateAsyncOperation = AndroidAssetPacks.GetAssetPackStateAsync(packNames);
I made sure that the Asset pack names are correct and everything, but since I cannot debug the inner call and see what is wrong there I am kinda lost now.
Any ideas what might be wrong with my setup? Tried to do everything according to the documentation.
Thanks for any insight.
Hi,
How are you launching your app? I mean locally or from Google Play, if locally then are launching directly from Unity?
Also, can you check AAB content that it actually includes asset packs and their names are correct?
We always upload it to Google Play internal and test it directly from the store.
I tried to check the AAB and it does include all asset packs with correct names. I’ll post a screenshot just to be sure.
Do I understand correctly that you’re trying to avoid automated asset packs downloading when required and AssetPacksManager.DownloadAllPacks is your own script? Is it possible for you to share the source?
If your goal to fit into the Google Play limits and you are downloading asset packs when app starts then it’s easier to use install-time asset packs. They are installed with the base module, but they are not included into the 200Mb limit. Of course manual downloading of on-demand asset packs also should work, but it’s hard to say what exactly is wrong without looking at your code.
The main thing we want to avoid is the dialog in app store that gives you warning to use Wifi over data which happens with install over 150mb.
I thought the install-time packs still contribute the the overall app install size, hence the dialog would still show up if I am not mistaken.
Here is my code that I use for downloading packs, it is called at the app start.
public void DownloadAllPacks()
{
Debug.Log($"[{GetType().Name}] Starting DownloadAllPacks");
if (stateAsyncOperation != null || downloadAsyncOperation != null)
{
Debug.LogError($"[{GetType().Name}] Different download operation is already running!");
return;
}
stateAsyncOperation = AndroidAssetPacks.GetAssetPackStateAsync(packNames);
if (stateAsyncOperation == null)
{
Debug.LogError($"[{GetType().Name}] Failed getting asset packs state!");
return;
}
foreach (AndroidAssetPackState item in stateAsyncOperation.states)
Debug.Log($"[{GetType().Name}] Received state info about pack. Name={item.name}, Status={item.status}");
coroutineRunner.StartCoroutine(CheckPackStates());
}
private IEnumerator CheckPackStates()
{
if (stateAsyncOperation != null)
{
yield return stateAsyncOperation;
AndroidAssetPackState[] requiredPacks = stateAsyncOperation.states.Where(x => x.status == AndroidAssetPackStatus.NotInstalled).ToArray();
foreach (AndroidAssetPackState item in requiredPacks)
Debug.Log($"[{GetType().Name}] Pack ready to be downloaded (not yet installed). Name={item.name}");
downloadAsyncOperation = AndroidAssetPacks.DownloadAssetPackAsync(requiredPacks.Select(x => x.name).ToArray());
if (downloadAsyncOperation == null)
{
Debug.LogError($"[{GetType().Name}] Failed getting asset packs download operation!");
yield break;
}
coroutineRunner.StartCoroutine(DownloadAwaiter());
}
}
private IEnumerator DownloadAwaiter()
{
if (downloadAsyncOperation != null)
{
yield return downloadAsyncOperation;
// Download finished
if (packNames.All(x => downloadAsyncOperation.downloadedAssetPacks.Contains(x)))
{
Debug.Log($"[{GetType().Name}] All packs were downlaoded succesfully.");
}
else
{
Debug.Log($"[{GetType().Name}] Some packs were not downloaded. {string.Join(",", downloadAsyncOperation.downloadFailedAssetPacks)}");
}
}
}
I think that your problem is in this line
foreach (AndroidAssetPackState item in stateAsyncOperation.states)
You should not try to check states until stateAsyncOperation.IsDone is true - Unity - Scripting API: Android.GetAssetPackStateAsyncOperation.states
Good point. I’ll go and try adjust the script and let you know if it worked.
Ok so we now finally got the packs downloaded, but we encountered different issue.
Our base is 163mb so we are still getting the wifi/data dialog during install. It seems that unity creates the packs but still includes everything in the base + install-time size.
Is there any way how to check or exclude assets that we have in the custom packs so they do not end up in the base module?
It’s hard to say what exactly is wrong. But if some addressables data are packed into on-demand packs they should not be included to the install-time data as well.
Try to investigate content and the size of the folders inside AAB file, install-time data are base, UnityDataAssetPack, AddressablesAssetPack.
I assume that your on-demand addressables assets should be inside RomeAssetPack and JapanAssetPack.
Found the cause of this. We had some deeply rooted reference through scriptable object that forced Unity to pack basically everything into the base module.
We managed to isolate the references and now the on-damand packs are properly separated from the base module.
It starting working fine but now we face some issues when restarting the app. It fails to load assets from the packs that were already downloaded.
I can try to help tomorrow if you provide more details and logcat from the device.
Right now we get app freezes/crashes when it tries to request the asset pack (probably load some asset at runtime)
My game froze with this in logcat, not really sure what to take from it, game just froze with no further error.
Seems that AsserPackServiceImpl linkToDeath, couldn’t find what this means exactly.
Yesterday you’ve mentioned that everything works on the first run.
So does this freeze happens after restart only?
Can you try to turn off your method which checks asset pack states and downloads them when app starts? In this case addressables.android package should take care of the downloading.
Well I have to check if the asset packs are present. Our you mean that i should just request the asset I need and it should be handled on the background?
We are now working on more specific repro for the bug. Once I have the details I will post it here.
Yes, addressables.android package takes care of asset packs downloading when you are requesting assets.
So what should be the ideal approach to check if the asset pack is present and I can skip the Status/Download part?
Here is proper log of what happens after we restart the app after the freeze.
2024/11/27 14:14:58.035 22384 25629 Info PlayCore UID: [10707] PID: [22384] AssetPackServiceImpl : getPackStates([RomeAssetPack, JapanAssetPack, AtlanteanAssetPack, BossesAssetPack])
2024/11/27 14:14:58.036 22384 25834 Info PlayCore UID: [10707] PID: [22384] AssetPackServiceImpl : Initiate binding to the service.
2024/11/27 14:14:58.069 22384 25966 Error Unity Unable to open archive file: jar:file:///data/app/~~O3iAOOHm2fd8pHwfvnlJCA==/com.tt-VY2Fe_6pK2wYeyHEuM0wHw==/split_UnityDataAssetPack.apk!/assets/aa/Android/localization-locales_assets_all.bundle
2024/11/27 14:14:58.072 22384 25966 Error Unity Unable to open archive file: jar:file:///data/app/~~O3iAOOHm2fd8pHwfvnlJCA==/com.tt-VY2Fe_6pK2wYeyHEuM0wHw==/split_UnityDataAssetPack.apk!/assets/aa/Android/romeassetpack_assets_all_7ddbe37a84d8aa12c9be8ca13071de03.bundle
2024/11/27 14:14:58.073 22384 25629 Error Unity Failed to read data for the AssetBundle 'localization-locales_assets_all.bundle'.
2024/11/27 14:14:58.073 22384 25629 Error Unity UnityEngine.AssetBundleCreateRequest:get_assetBundle()
2024/11/27 14:14:58.073 22384 25629 Error Unity UnityEngine.ResourceManagement.ResourceProviders.AssetBundleResource:LocalRequestOperationCompleted(AsyncOperation)
2024/11/27 14:14:58.073 22384 25629 Error Unity UnityEngine.ResourceManagement.ResourceProviders.AssetBundleResource:WaitForCompletionHandler()
2024/11/27 14:14:58.073 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:WaitForCompletion()
2024/11/27 14:14:58.073 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle:WaitForCompletion()
2024/11/27 14:14:58.073 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.GroupOperation:InvokeWaitForCompletion()
2024/11/27 14:14:58.073 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:WaitForCompletion()
2024/11/27 14:14:58.073 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1:WaitForCompletion()
2024/11/27 14:14:58.073 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.ProviderOperation`1:InvokeWaitForCompletion()
2024/11/27 14:14:58.073 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:WaitForCompletion()
2024/11/27 14:14:58.073 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.Asyn
2024/11/27 14:14:58.074 22384 25629 Error Unity RemoteProviderException : Invalid path in AssetBundleProvider: 'jar:file:///data/app/~~O3iAOOHm2fd8pHwfvnlJCA==/com.tt-VY2Fe_6pK2wYeyHEuM0wHw==/split_UnityDataAssetPack.apk!/assets/aa/Android/localization-locales_assets_all.bundle'.
2024/11/27 14:14:58.074 22384 25629 Error Unity UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
2024/11/27 14:14:58.074 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:set_OperationException(Exception)
2024/11/27 14:14:58.074 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:Complete(TObject, Boolean, Exception, Boolean)
2024/11/27 14:14:58.074 22384 25629 Error Unity UnityEngine.ResourceManagement.ResourceProviders.AssetBundleResource:CompleteBundleLoad(AssetBundle)
2024/11/27 14:14:58.074 22384 25629 Error Unity UnityEngine.AsyncOperation:InvokeCompletionEvent()
2024/11/27 14:14:58.074 22384 25629 Error Unity UnityEngine.AssetBundleCreateRequest:get_assetBundle()
2024/11/27 14:14:58.074 22384 25629 Error Unity UnityEngine.ResourceManagement.ResourceProviders.AssetBundleResource:LocalRequestOperationCompleted(AsyncOperation)
2024/11/27 14:14:58.074 22384 25629 Error Unity UnityEngine.ResourceManagement.ResourceProviders.AssetBundleResource:WaitForCompletionHandler()
2024/11/27 14:14:58.074 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.AsyncOperatio
2024/11/27 14:14:58.075 22384 25629 Error Unity Failed to read data for the AssetBundle 'romeassetpack_assets_all_7ddbe37a84d8aa12c9be8ca13071de03.bundle'.
2024/11/27 14:14:58.075 22384 25629 Error Unity UnityEngine.AssetBundleCreateRequest:get_assetBundle()
2024/11/27 14:14:58.075 22384 25629 Error Unity UnityEngine.ResourceManagement.ResourceProviders.AssetBundleResource:LocalRequestOperationCompleted(AsyncOperation)
2024/11/27 14:14:58.075 22384 25629 Error Unity UnityEngine.ResourceManagement.ResourceProviders.AssetBundleResource:WaitForCompletionHandler()
2024/11/27 14:14:58.075 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:WaitForCompletion()
2024/11/27 14:14:58.075 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle:WaitForCompletion()
2024/11/27 14:14:58.075 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.GroupOperation:InvokeWaitForCompletion()
2024/11/27 14:14:58.075 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:WaitForCompletion()
2024/11/27 14:14:58.075 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1:WaitForCompletion()
2024/11/27 14:14:58.075 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.ProviderOperation`1:InvokeWaitForCompletion()
2024/11/27 14:14:58.075 22384 25629 Error Unity UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:WaitForCompletion()
2024/11/27 14:14:58.075 22384 25629 Error Unity UnityEngine.ResourceManag
2024/11/27 14:14:58.075 22384 25629 Error Unity RemoteProviderException : Invalid path in AssetBundleProvider: 'jar:file:///data/app/~~O3iAOOHm2fd8pHwfvnlJCA==/com.tt-VY2Fe_6pK2wYeyHEuM0wHw==/split_UnityDataAssetPack.apk!/assets/aa/Android/romeassetpack_assets_all_7ddbe37a84d8aa12c9be8ca13071de03.bundle'.
It seems it completely fails to work with the downloaded packs.
Where are these files inside of your AAB
localization-locales_assets_all.bundle
romeassetpack_assets_all_7ddbe37a84d8aa12c9be8ca13071de03.bundle
?
Converted my build to ZIP and these are the paths within the AAB:
FreshBuild_310.zip\LocalizationLocales\assets\aa\Android\localization-locales_assets_all.bundle
FreshBuild_310.zip\RomeAssetPack\assets\aa\Android\romeassetpack_assets_all_7ddbe37a84d8aa12c9be8ca13071de03.bundle
Can you check both com.unity.addressables and com.unity.addressables.android package versions?