Unity 生成 Android App Bundle(aab) (三)

aab命令手机安装

aab转apks

C:/g/Java/jdk1.8.0_231\bin\java.exe -jar "插件下载地址\UnityProj\Assets\GooglePlayPlugins\com.google.android.appbundle\Editor\Tools\bundletool-all.jar" build-apks --bundle="D:\aab.aab" --output="D:\aab.apks" --ks=F:\keyStore\keystore.keystore --ks-pass=pass:pass --ks-key-alias=alias  --mode=persistent --local-testing

 

apks安装

C:/g/Java/jdk1.8.0_231\bin\java.exe -jar "插件下载地址\UnityProj\Assets\GooglePlayPlugins\com.google.android.appbundle\Editor\Tools\bundletool-all.jar" install-apks --adb="D:\android-sdk-windows\platform-tools\adb.exe" --apks="D:\aab.apks"

 

 

AssetDeliveryErrorCode错误返回

 
 

AssetBundles 流程

1、用PlayAssetDelivery.IsDownloaded判断是否下载完毕
2、下载完毕的,加载assetbundle
PlayAssetBundleRequest bundleRequest = PlayAssetDelivery.RetrieveAssetBundleAsync(assetBundleName);
//这里会调用 ProcessPackStateUpdate,就是一直报错的地方,资源加载中(这里应该是加载资源到指定位置(资产包正在下载并转移到应用程序的存储),因为例子中有 installtime,这个没有触发ProcessPackStateUpdate,fastfollow触发了ProcessPackStateUpdate)

while (!bundleRequest.IsDone)
{
yield return null;
}
Debug.Log($"LoadAssetBundlesFromAssetPacks assetBundleName:{assetBundleName} bundleRequest.Error:{bundleRequest.Error.ToString()} bundleRequest.Status:{bundleRequest.Status.ToString()}");

if (bundleRequest.Error == AssetDeliveryErrorCode.NoError)
{
gameAssetManager.AddAssetBundle(assetBundleName,
bundleRequest.AssetBundle);

3、没有下载的手动下载
先获得包大小 PlayAssetDelivery.GetDownloadSize(assetPackName);
请求下载
PlayAssetDelivery.RetrieveAssetBundleAsync(assetPackName);
触发下载进度值 ProcessPackStateUpdate,这里会修改assetBundleRequest.DownloadProgress
更新下载进度 assetBundleRequest.DownloadProgress
下载完成清除 gameAssetPack.FinishBundleDownload()


AssetPack 流程

1、是否下载完毕 PlayAssetDelivery.IsDownloaded
2、下载完毕的,加载
PlayAssetDelivery.RetrieveAssetPackAsync(assetPackName);

while (!packRequest.IsDone)
{
yield return null;
}

if (packRequest.Error == AssetDeliveryErrorCode.NoError)
{
3、没有下载的手动下载
先获得包大小 PlayAssetDelivery.GetDownloadSize(assetPackName);
请求下载
PlayAssetDelivery.RetrieveAssetPackAsync(assetPackName);
这里需要检测下载状态,是否下载异常和蜂窝网络assetPackRequest.Status
触发下载进度值 ProcessPackStateUpdate,这里会修改 assetPackRequest.DownloadProgress
更新下载进度 assetPackRequest.DownloadProgress
下载完成清除 gameAssetPack.FinishPackDownload();

posted @ 2022-02-21 19:22  酉乐  阅读(559)  评论(0编辑  收藏  举报