When creating a build of your game for Amazon Underground, it’s important to make sure that your APK has a unique bundle identifier and an icon with the Underground sash. These two requirements help make your Underground game stand out when installed on a player’s device and also help avoid any installation conflict you may have with the paid version of your game. You can learn more about these requirements from our dev portal here. If you are building a Unity Game, you already know that there isn’t an easy way to create separate Android builds per target. Once you configure the build, it's the same for all Android platforms. To get around this, we are going to talk about a plugin called Advanced Builder which will help you not only automate your different builds but also allows you to write a custom build script to change out icons based on whether it’s an Underground version or a standard one. Let’s get started.
Advanced Builder is paid plugin on the Unity Asset store that allows you to set up individual builds based on target platforms and automate a lot of the tedious build steps. Once you have it installed you can create a new release type for the Underground build. Here you can see I have a Standard build and my Underground Build.
One thing to note is that each release type has its own bundle identifier.
Next, setting up a build for the Amazon Appstore is as easy as checking Amazon Store in the Distribution platforms area.
Also, you can set each of the Android Architectures individually. Since Amazon devices are ARMv7 compatible I don’t do builds for FAT or x86.
Once you have everything setup, you can create your individual builds for the Amazon Appstore, Underground and any other platforms you distribute your game on.
Before we do the build, we are going to want to create a custom build script that lets us swap out the icons based on the release type.
Advanced Builder allows you to set custom C# scripts that run logic before and after the build. To make one, create an Editor folder in your project and add a new C# class to it. You’ll want to also make that class implement the IAdvancedCustomBuild interface. There are two methods you’ll need to add:
public void OnPreBuild(Configuration configuration, System.DateTime buildDate)
{
}
public void OnPostBuild(Configuration configuration, System.DateTime buildDate)
{
}
Once you have the script in your project, add it to Advanced Builder’s Custom Settings.
From here we will create a method that looks at the current build, gets the icons from that platform and loads them from a target folder. You’ll need a property at the top of your class that points to where your icons will be stored:
public const string ICON_PATH = "Assets/DragonSweeper/Artwork/Icons/";
Next we’ll need a way to convert the BuildTarget supplied by Advanced Builder into a BuildTargetGroup to use with the PlayerSettingsClass. Add the following static method:
public static BuildTargetGroup ConvertToGroup(BuildTarget buildTarget)
{
BuildTargetGroup targetGroup = BuildTargetGroup.Unknown;
switch (buildTarget)
{
case BuildTarget.Android:
targetGroup = BuildTargetGroup.Android;
break;
default:
throw new ArgumentOutOfRangeException("buildTarget");
}
return targetGroup;
}
Unity supports a lot of different platforms so simply add a new case based on the ones your game will target. Here, I am simply supporting Android.
Now we need to find all the icons size for a specific platform. Create the following method:
private static void AssignPlayerSettingsIcons(BuildTarget target, ReleaseType releaseType)
{
var targetGroup = ConvertToGroup(target);
int[] iconSizeArray = PlayerSettings.GetIconSizesForTargetGroup(targetGroup);
Texture2D[] iconArray = new Texture2D[iconSizeArray.Length];
for (int i = 0; i < iconSizeArray.Length; i++)
{
var path = ICON_PATH + releaseType.name + "/icon-" + iconSizeArray[i] + ".png";
Debug.Log("Icon Path "+ path)
Texture2D iconTexture = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D;
if (iconTexture != null)
{
iconArray[i] = iconTexture;
}
else
{
Debug.LogError("Error, could not find icon with size : " + iconSizeArray[i]);
}
}
PlayerSettings.SetIconsForTargetGroup(targetGroup, iconArray);
}
As you can see, we generate out a unique path to each icon based on the name of the release in Advanced Builder. We push that path into an array that Unity will use to package up the game with. The final thing we need to do is call this method in OnPreBuild and pass in the values it needs:
public void OnPreBuild(Configuration configuration, System.DateTime buildDate)
{
AssignPlayerSettingsIcons(configuration.platformArchitecture.buildTarget, configuration.releaseType);
}
Now our custom build script is ready. We just need to create the icons and put them in the correct folder.
Your Underground game will need to use a custom sash. You can find out more about this here. I’ve gone ahead and created icons for Android’s 6 sizes (192, 144, 96, 72, 48 and 36) with the Underground sash template.
I also have the same icons for my standard build and I put both of them in my Asset folder.
Now when we run our builds, Advanced Builder will include the right icons for my standard and Underground APK.
After we do our build, you’ll now have folder for each APK. Here you can see the Amazon Store folder contains our standard and Underground APKs.
You can always do a quick test to make sure this worked by turning the .apk into a .zip, unzipping it and looking at the icons in the resources folder.
And that’s it! Now you can easily create your Underground builds from the same project and leverage your existing codebase.
Amazon Underground is a new app for Android phones. It has all of the functionality of our regular Amazon mobile shopping app, plus an exciting addition: more than twenty thousand dollars in apps, games, and in-app items that are 100% free for customers. For you app developers, Amazon Underground includes a new monetization model where Amazon pays you based on the amount of time your app is used. With Amazon Underground, you can turn 100% of your Android users into revenue-generating customers.
To learn more about Amazon Underground and the Amazon Appstore be sure to check out the following links.
- Jesse Freeman (@jessefreeman)