Book Image

Unity 5 for Android Essentials

By : Valera Cogut
Book Image

Unity 5 for Android Essentials

By: Valera Cogut

Overview of this book

Table of Contents (14 chapters)
Unity 5 for Android Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

APK expansion files in Unity 5


Google Play requires that the size of your games and applications does not exceed 50 MB. For most applications and games, this size is enough. Alternatively, you may want to have fantastic graphics for your projects and other huge media files that can take up a lot of space. Google Play makes a developer's life simpler and easier by expanding an APK file by large expansion files. Extension files are kept in a shared folder storage of the device where your game has enough access rights.

Overview

Each file cannot be larger than 2 GB, and you can choose any format for it. Of course, the best way is to use only compressed files in order to conserve bandwidth while the downloading process is active. You can add only one or two expansion files to your APK. Behind each expansion file lies its meaning:

  • The first expansion file is known as the main and should be used for extra resources needed in your game. That's why this expansion file is primary.

  • The second expansion file is known as patch, and is required to update the main file. That's why it is optional.

You should know that the Developer Console does not allow you to update your existing APK file by uploading only a new expansion file.

Formats

For your expansion files, you can use any desired format, such as MP3, MP4, AVI, RAR, ZIP, DOC, and PDF. The JOBB tool can help you encapsulate and encrypt your resources and patches for them.

The updating process

In most cases, Google Play will do all jobs automatically for you. So, very often, you don't need to do anything while users will download or upload your expansion files on their devices. However, sometimes your game has to download these files itself by receiving a URL from Google Play's application licensing service.

The basic steps to download expansion files for your game are listed as follows:

  1. On the game start event, you should look for the expansion files in the Android/obb/<package-name>/ directory.

  2. In the first step, if you will find that your expansion files are already in that directory, then you can continue playing your game further.

  3. In the event that the expansion files are not in that directory, you should perform the next two steps.

  4. You have to receive URLs, names, and sizes for your game's expansion files. Before downloading anything, you should know where and what to download.

  5. After having all the required information to download the expansion files, you can get your files and put them into the Android/obb/<package-name>/ directory with the same name as Google Play told you.

Note

The following notes that are listed are taken from the official Android Developers Documentation page at http://developer.android.com/google/play/expansion-files.html:

  • The URL that Google Play provides for your expansion files is unique for every download, and each one expires shortly after it is given to your application.

  • Whether your application is free or not, Google Play returns the expansion file URLs only if the user acquired your application from Google Play.

  • A variety of errors may occur during the request and download that you must gracefully handle.

  • Network connectivity can change during the download, so you should handle such changes. If interrupted, resume the download when possible.

  • While the download occurs in the background, you should provide a notification that indicates the download progress, notifies the user when it's done, and takes the user back to your application when selected.

Setting up expansion files in Unity 5

Navigate to the Player Settings | Publishing Settings menu, and at the bottom you will see an option called Split Application Binary. When this option is enabled, your project will be divided into the .apk file for code, and for all other assets and data, it will be the .obb file.

Let's look at a list of key aspects related to the loading of the expansion files (.obb):

  • The expansion files do not need to be uploaded to the server Google Play.

  • If you have decided to publish .apk and .obb files on Google Play, then you need to include the code to download the expansion files.

  • In the Unity Asset Store, you can find a great plugin for downloading and extracting your expansion files in the right location. The URL of this plugin is http://u3d.as/content/unity-technologies/google-play-obb-downloader/2Qq.

  • Before testing the .obb files, you need to be logged in your Google account.