Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity setting Player Settings Target Architectures via Script

Tags:

c#

unity3d

I have my custom build script and I want to add more options in it. One of them is Target Architectures. (I'm using IL2CPP as a scripting backend - I set it by script)

Here you can see which settings I want to change:

According to docs I can use PlayerSettings.SetArchitecture(), but it seems not to work for me at all. It only has an option for 0 - None, 1 - ARM64, 2 - Universal and I want All. So I tried using:

PlayerSettings.SetArchitecture(BuildTargetGroup.Android, unchecked((int)AndroidArchitecture.All));

but it doesn't change anything, also the lines below does not change anything:

PlayerSettings.SetArchitecture(BuildTargetGroup.Android, unchecked((int)AndroidArchitecture.ARM64));
PlayerSettings.SetArchitecture(BuildTargetGroup.Android, unchecked((int)AndroidArchitecture.ARMv7));
PlayerSettings.SetArchitecture(BuildTargetGroup.Android, unchecked((int)AndroidArchitecture.X86));

I'm wondering how I can do it correctly?

like image 579
sswwqqaa Avatar asked Aug 15 '18 19:08

sswwqqaa


1 Answers

The second parameter of the PlayerSettings.SetArchitecture function expects 0 for None, 1 for ARM64 and 2 for Universal. This is not what you are really looking for.


With the screenshot in your question, you are looking for the PlayerSettings.Android.targetArchitectures property which can be used to set ARM64, ARMv7 or X86 as the build architecture with the AndroidArchitecture enum.

To set only one architecture:

PlayerSettings.Android.targetArchitectures = AndroidArchitecture.X86;

To set only multiple architecture, use enum flags since AndroidArchitecture is declared with the Flags attribute which allows the bitwise manipulations to be used to select multiple values:

AndroidArchitecture aac = AndroidArchitecture.ARM64 | AndroidArchitecture.ARMv7 | AndroidArchitecture.X86;
PlayerSettings.Android.targetArchitectures = aac;

or

AndroidArchitecture aac = AndroidArchitecture.ARM64;
aac |= AndroidArchitecture.ARMv7;
aac |= AndroidArchitecture.X86;   
PlayerSettings.Android.targetArchitectures = aac;

You can learn more about enum flags here.

If you just want to use all the architectures then simply use AndroidArchitecture.All.

PlayerSettings.Android.targetArchitectures = AndroidArchitecture.All;
like image 73
Programmer Avatar answered Nov 14 '22 22:11

Programmer