Bootstrap

Unity Android AAB包GooglePlay上线备忘

aab

GooglePlay要求新上线的App必须使用aab格式提交,在Unity Build Settings中勾选Build App Bundle 选项即可;或者在代码中设置:

EditorUserBuildSettings.buildAppBundle = true;

安装测试

https://developer.android.com/tools/bundletool?hl=zh-cn

下载bundleTool工具jar包,使用以下命令生成apks文件:

bundletool build-apks --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks
--ks=/MyApp/keystore.jks
--ks-pass=file:/MyApp/keystore.pwd
--ks-key-alias=MyKeyAlias
--key-pass=file:/MyApp/key.pwd

使用以下命令进行安装:

bundletool install-apks --apks=/MyApp/my_app.apks

targetAPI 33

GooglePlay要求App targetAPI Level必须大于等于33,而Unity 2022.3版本默认auto选项是32版本,这里需要手动将PlayerSetting中的Target API Level选择为API level33。

上传证书的密钥强度太低

这并不是签名的密码太简单,而是旧签名文件的密钥是1024位,现在要求2048位以上。使用keytool命令重新创建keystore,注意选择密钥2048位。

💡 另外:密钥库类型建议升级为PKCS12

您的App Bundle包含的以下配置会使应用的初始安装大小超过200MB

GooglePlay要求aab的base部分不能超过200MB,解决该问题需要使用Play Asset Delivery。

https://docs.unity3d.com/2022.3/Documentation/Manual/android-asset-packs-set-up.html

Unity中处理很简单,只需要:

  1. 勾选Build App Bundle选项;
  2. 在PlayerSetting/Other Settings中,勾选Split Application Binary选项。

解决打包报错

再打包,可能会报错类型重复,例如:

Duplicate class android.support.v4.graphics.drawable.IconCompatParcelizer found in
modules core-1.0.0-runtime                (androidx.core:core:1.0.0)
and
jetified-androidx.core.core-1.2.0-runtime (androidx.core.core-1.2.0)

看起来依赖库重复包含了,找了一些解决方法,比如:exclude部分包,结果会出现运行时错误。

对于Unity 2022.3.0f版本,最简单有效的解决方法如下:

https://github.com/firebase/firebase-unity-sdk/issues/661#issuecomment-1803420952

the fix from Unity that works for me (I use only GooglePlayGames and GoogleMobileAds plugins):

1 - clean up all aar and jar files and also their metafiles from Assets/Plugins/Android folder
2 - delete Library/Bee/Android/Prj/IL2CPP/Gradle folder
3 - open project
4 - check that Custom Main Gradle Template, Custom Gradle Settings Template, Custom Gradle Properties Template are turned on in Player settings
5 - run Assets/Eternal Dependency Manager/Android Resolver/Resolve (it should end immediately, there should be no new files in Assets/Plugins/Android appear)
6 - build AAB

;