Unity3D安卓打包参数配置与兼容性的关系分析

前言

在使用Unity3D工程导出安卓安装包的时候,往往会遇到兼容性的问题,针对某些机型,要么无法打开游戏,要么会出现卡机的现象。面对这种情况,我们可以调节相关的参数来提高兼容性。

为了了解在打包时候每个参数的含义,我们查找了Unity3D的官方文档。为了清楚每个参数所起的作用以及每个参数对兼容性的影响因素,我们有针对性的做了对比实验,然后在安卓云测试平台(http://www.testin.cn)测试兼容性,将最终结果进行比较,最后提出优化方案。

文档说明

功能介绍

Unity4.5安卓打包参数配置主要讲述Unity4.5在进行安卓打包时遇到的一些参数,这些参数的详细解释,以及如何通过修改参数来提高游戏的兼容性。本文主要描述如何配置打包参数,供Unity4.5输出安卓包的工作人员使用。

阅读对象

本文档面向了解Android,Unity3D客户端的开发人员。

配置参数详解

一.Rendering Path(This property is sharedbetween Standalone and WebPlayer content)

渲染路径,这个属性一般在PC上或者网页上比较有用,一般有如下三个选项

Vertex Lit(Lowest lighting fidelity, no shader support.Best used on old machines or limited mobile platforms)

顶点光源模型。不支持shader,在一些旧的机器上或者受限制的机器上最好使用这个选项

Forward(Good support for lighting features; limitedsupport for shadows)

对光的特征支持的很好,但是对阴影支持的不好

Deferred Lighting(Best support for lighting and shadowingfeatures, but requires certain level of hardware support. Best used if you havemany realtime lights. Unity Pro only)

对光的特征和阴影支持的很好,前提是支持硬件加速,如果做实时渲染最好使用这个选项,只有pro版本支持。

 

二.Graphics Level(Select either ES 1.1 (‘fixed function’) or ES 2.0 (‘shader based’) Open GL level. Whenusing the AVD (emulator) only ES 1.x is supported.)

图像等级。在OpenGLES 2.0(支持阴影)和3.0还有1.x(功能性)之间选择,当只用到模拟器的时候,只有ES1.x才支持。

Automatic

自动选择

Force OpenGLES 2.0

强制OpenGL ES2.0

Force OpenGLES 3.0

强制OpenGL ES3.0

 

三.Install Location

安装路径。

PreferExternal

优先外部

Automatic

自动选择(一般都是自动选择,而且兼容性更好)

ForceInternal

强制安装在内部闪存中

 

 

四.Write Access

写入权限

InternalOnly

只能写在内部

External(SDCard)

写在外部SD卡中,对应安卓的写入权限:android.permission.WRITE_EXTERNAL_STORAGE

 

五.Api Compatibility Level

使用.Net的版本

.Net 2.0Subset

.Net2.0的子集,占用较小的空间

.Net 2.0

.Net2.0完全集合,占用较大的空间

 

六.Stripping Level

选择抽出的脚本功能来减少了包的大小(iOS和Android都可以选择)

Disabled

不减少功能

StripAssemblies

减少程序集合

StripByteCode

减少字节码

Use micromscorlib

使用迷你库,前两者都减少

 

七.Optimize Mesh Data*

对于材料没有必要的数据,可以移除的数据进行优化

 

八,Multithreaded Rendering

多线程渲染

 

九.GPU Skinning*

是否使用GPU着色

 

十.Static Batching

是否激活静态度量,默认是激活状态,只有pro版本有效。

 

十一.Dynamic Batching

是否激活动态度量,默认是激活转台。

实验数据

实验方法

该实验采取对照实验的方法。如果要考察单个参数对于兼容性的影响,必须得控制另外的参数不变。然后针对不同的配置参数打包,上传到云测试平台进行兼容性测试。

实验操作流程

对要进行测试的参数进行设计。

主要涉及到如下几个参数

1.        Graphics Level(GL)

2.        Install Location(IL)

3.        Api Compatibility Level(ACL)

4.        Stripping Level(SL)

5.        Optimize Mesh Data*(OMD)

6.        Multithreaded Rendering*(MR)

7.        GPU Skinning*(GK)

8.        Write Access(WA)

9.        Rendering Path(RP)

10.     Static Batching(SB)

11.     Dynamic Batching(DB)

设计对照组方案

序号 GL IL ACL SL OMD MR GK WA RP SB DB
1 2.0 external 2.0subset disable false false false Internal only Forward true true
2 auto external 2.0subset disable false false false Internal only Forward true true
3 3.0 external 2.0subset disable false false false Internal only Forward true true
4 auto auto 2.0subset disable false false false Internal only Forward true true
5 auto internal 2.0subset disable false false false Internal only Forward true true
6 auto internal 2.0 disable false false false Internal only Forward true true
7 auto internal 2.0subset Assemblies false false false Internal only Forward true true
8 auto internal 2.0subset ByteCode false false false Internal only Forward true true
9 auto internal 2.0subset mscorlib false false false Internal only Forward true true
10 auto internal 2.0subset disable true false false Internal only Forward true true
11 auto internal 2.0subset disable true true false Internal only Forward true true
12 auto internal 2.0subset disable true true true Internal only Forward true true
13 auto internal 2.0subset disable true true true SDCard Forward true true
14 auto internal 2.0subset disable true true true Internal only VertexLit true true
15 auto internal 2.0subset disable true true true Internal only Defferred Lig true true
16 auto internal 2.0subset disable true true true Internal only Forward false true
17 auto internal 2.0subset disable true true true Internal only Forward true false

 

 

针对每一个设计方案打包。

将上述的17个方案进行打包分别命名为001-017.apk

将打好的安装包进行兼容性测试。

将这17个安装包上传给testin网站,进行兼容性测试

得到测试结果后,得出每个参数的最优化配置。

   

正常

启动(s) CPU(%) 内存(M) 包体
序号 通过率 安装 启动 卸载 平均值 峰值 平均值 峰值 平均值 峰值  
001 74.30 87.30 85.1 100 0.91 11.67 9.70 100 19.52 66.75 8205
002 66.34 82.80 80.1 100 0.95 13.09 9.47 100 17.82 66.87 8205
003 67.44 82.70 81.5 100 0.94 11.14 9.35 100 17.46 65.63 8205
004 70.21 83.00 84.6 100 1.03 12.42 8.81 100 17.33 65.81 8205
005 69.86 83.30 83.8 100 1.02 10.81 8.82 100 17.61 66.88 8205
006 73.96 87.20 84.9 100 1.10 12.18 9.00 100 19.09 66.01 8972
007 73.81 87.10 84.8 100 1.02 11.12 9.01 100 18.25 65.19 7243
008 80.20 90.80 88.3 100 1.14 11.27 9.13 100 19.85 60.29 7243
009 82.43 90.90 90.7 100 1.13 11.50 9.13 100 19.79 60.46 7243
010 79.68 90.20 88.4 100 1.04 10.93 9.40 100 21.29 68.79 8205
011 78.93 89.00 88.7 100 1.01 10.84 9.96 100 23.41 77.06 8205
012 78.55 89.00 88.3 100 1.00 11.24 11.24 100 23.68 77.04 8205
013 87.79 97.30 90.2 100 0.92 10.76 11.80 100 25.76 72.27 8205
014 88.76 98.00 90.6 100 1.02 11.11 10.90 100 25.36 75.57 8205
015 92.70 99.20 94.5 100 1.23 11.20 10.84 100 26.87 71.95 8205
016 93.17 98.00 95.1 100 1.15 11.72 11.61 100 26.34 72.01 8205
017 88.00 97.60 90.2 100 1.11 10.90 11.17 100 25.87 71.96 8205

 

对照组信息表

序号 参数 对照组 优化顺序
1 Graphics Level 001:002:003 ES2.0 > ES3.0 > Automatic
2 Install Location 002:004:005 Automatic > Force Internal > Prefer External
3 Api Compatibility Level 005:006 .Net2.0 > .Net2.0 Subset
4 Stripping Level 005:007:008:009 Use micro mscorlib > Strip ByteCode > Strip Assemblies > Disable
5 Optimize Mesh Data* 005:010 True > false
6 Multithreaded Rendering* 010:011 False > true
7 GPU Skinning* 011:012 False > true
8 Write Access 012:013 SDCard > Internal Only
9 Rendering Path 012:014:015 Deferred Lighting > VertexLit > Forward
10 Static Batching 012:016 False > true
11 Dynamic Batching 012:017 False > true

上表就是实验的最终结果,可以用来指导Unity3D的安卓打包。

 

在unity打包的时候还有一个系统最低版本的适配问题,比如支持最低在安卓系统2.3.3上运行。

为了考察支持最低安卓系统版本对于兼容性的影响。我也做了系统的对比实验。

序号 最低版本 目标版本
1 10 14
2 11 14
3 12 14
4 14 14

以下是测试结果:

 

   

正常

启动(s) CPU(%) 内存(M) 包体
序号 通过率 安装 启动 卸载 平均值 峰值 平均值 峰值 平均值 峰值  
1 88.10 95.8 91.9 100 0.94 10.29 14.95 100 22.37 66.10 7363
2 89.74 91.0 98.6 100 1.09 4.32 11.08 100 25.81 65.69 7363
3 90.24 92.1 98.0 100 1.28 11.30 12.75 100 23.88 65.75 7363
4 90.12 92.0 98.0 100 1.23 10.72 12.41 100 23.84 66.07 7363

由于现在的主流安卓系统的版本都比较高(都大于4.0 API level = 14),所以我们将目标版本设置为14。至于最低的版本,从数据上来看2.3.3(API level = 10)和4.0.0(API level = 14)差别不是很大。所以最低系统版本的选择对于兼容性的效果提升也不是那么明显。介于历史残留问题,现在使用2.3.3版本的人数还很多,故可以将系统最低版本设置为10。

 

为了考察支持目标版(targetsdk level)本对于兼容性的影响,我也做了系统的对比实验。

序号 最低版本 目标版本
1 10 10
2 10 11
3 10 12
4 10 13
5 10 14

一下是测试结果:

   

正常

启动(s) CPU(%) 内存(M) 包体
序号 通过率 安装 启动 卸载 平均值 峰值 平均值 峰值 平均值 峰值  
1 85.62 95.8 87.4 100 0.90 10.62 14.70 100 21.60 65.60 7363
2 80.37 91.0 81.9 100 0.86 10.44 12.40 100 21.62 75.63 7363
3 81.93 92.1 84.0 100 0.79 1.58 12.96 100 24.13 75.43 7363
4 87.23 92.0 89.5 100 0.90 10.70 14.67 100 21.44 75.40 7363
5 88.10 95.8 91.9 100 0.94 10.29 14.95 100 22.37 66.10 7363

 

从上表的结果可以看出,通过率最高的是序号5,也就是min tarlevel = 10,target sdk level = 14,target level 11,12,13 是不推荐的版本(连谷歌都不推荐)。

现在用户所用的版本大都是>4.0的,所以使用target level = 14是不错的选择。

有很多的app在使用的时候需要系统资源,比如联网,比如GPS等等,那么这些都是怎么实现的呢?

很简单只要使用android.provider.Settings这个类就可以了。

比如需要打开GPS操作:

[JavaScript]  纯文本查看 复制代码
1
2
Intent settingsIntent = new  Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(settingsIntent);
 

以此类推。

猜你喜欢

转载自blog.csdn.net/j_xiang/article/details/80026510