reducing ue4 apk tutorial

in Android, Tutorials, UE4

Reducing APK size

We have finished the development of our game but we have one more task to do before send it to publish, reduce the APK size to be as small as possible.

Google Play has set a size limit of 50MB for APKs that target Android 3.2 and lower (API level 13 or lower) and 100MB for Android 4.0 and higher (API level 14 or higher).

We can achieve this usign the next tips:

Don’t use starter content

If you followed the previous tutorial about setup of project you can jump to the next tip. If you have check the Starter Content on creation you need to create an empty project and use de Migration tool  over the content that you want to use.


Packaging settings

We need to go to Edit -> Project settings.

ue4_menu

On Packaging section, click on the bottom arrow of the Packaging settings to expose the Advanced Project Settings,

ue4_expand
Expand Advanced settings

and check:

  • Create compressed cooked packages
  • Share Material Shader Code
  • Share Material Native Libraries
  • Exclude editor content when cooking

Uncheck Cook everything in the project content directory(ignores list of maps below) and fill the list of maps to include in a packaged build with relative path /Game/Maps/xxx

ue4_project_settings
Packaging settings

If you obtain the error Package Native Shader Library failed for Android_ETC1 during packing process you must uncheck 

  • Share Material Shader Code
  • Share Material Native Libraries

On project section check, on Shipping build configuration.

  • Full Rebuild
  • For Distribution

Rendering settings

Max Dynamic Point Lights can help reduce the number of shaders that are generated for dynamic lights. If the game don’t use dynamic lighting you can disable it setting a value from 4 to 0

ue4_project_settings_2
Rendering settings

Removing unnecesary plugins

Some plug-ins require a particular set of base assets and code to work correctly. If the plug-in is not disabled, the assets and code that are needed to make the plug-in work will not be removed from our project.

On Main Toolbar click on the Edit option and then selecting the Plug-in.

ue4_project_menu

Now you can disable the plugin uncheking the Enable check

ue4_plugins

This is my unckeck list for the sample, it can be different for your game, so make sure you thoroughly test your project to ensure that the plug-ins you are disabling do not interfere with the functionality of your project.

  • Alembic Importer
  • Android media player
  • Android movie player
  • Apple movie player
  • Archvis character
  • Audio capture
  • AVF media player
  • Cable component
  • CharacterAI
  • CodeLite Integration
  • Facial Animation Bulk Importer
  • Google cloud Messaging
  • Kdevelop Integration
  • OculusVR
  • Perforce
  • Physx Vehicles
  • SpeedTree Importer
  • SteamVR
  • Subversion
  • UObject example plugin
  • Windows Movie player
  • WMF media player
  • XCode Integration

We can do an IDE restart and our first build at this point. Dont forget to select the shipping configuration. File->Package Project->Build Configuration->Shipping and then File->Package Project->Android->Andorid(ETC1)

ue4_package

Check cooked content

To ensure that only the content that is related to your project is added to your APK file, you can check which content is being added to your project’s APK by looking in the Cooked folder in your project. You can find the Cooked folder by going to (ProjectName)\Saved\Cooked and then choose the folder with the format you cooked your project for. You will only be able to see the content in the Cooked folder after you complete your first cook.

ue4_cooked
Cooked android folder

Package black list

You can now place a text file in your project’s Build/Platform/(Target Platform Folder) directory that will tell the cooker to exclude partial or complete file paths from being packaged into your project. Projects can have multiple Black List files for Debug, Development, Test, and Shipping builds that can be setup to include or exclude whatever project data you want.

You can exclude DefaultBloomKernel, this file is not needed for mobile, we will never use FFT bloom.

ue4_blacklist
Expert mode (Do a backup of the edited files before the dissaster)

If our game only use the lib of ads from google play services we can edit de MainActivity template to remove the references of google play services and avoid the inclusion of some libs. This change will affect to all android games, besides we will apply the changes on the engine files.

Edit the arr-import.txt from the UE4 installation Engine/Build/Android/Java and remove:

com.google.android.gms,play-services-auth,9.8.0
com.google.android.gms,play-services-games,9.8.0
com.google.android.gms,play-services-nearby,9.8.0
com.google.android.gms,play-services-plus,9.8.0

and change the ads version to the ads-lite version

com.google.android.gms,play-services-ads,9.8.0
com.google.android.gms,play-services-ads-lite,9.8.0
ue4_aar_imports_original
aar-imports.txt original
ue4_aar_imports_mod
aar-imports.txt Modified

Now we can edit the GameActivity to remove the lib references, we can remove the GoogleApiClient implementations and little more.

We can find the GameActivity.java on Engine\Build\Android\Java\src\com\epicgames\ue4

I will attach both files, original and modified, you can compare the files using some tool like WinMerge and apply the changes on your file manually, dont forget to make a backup of your file!!.

Tutorial files

Support this blog!

For the past year I've been dedicating more of my time to the creation of tutorials, mainly about game development. If you think these posts have either helped or inspired you, please consider supporting this blog. Thank you so much for your contribution!

Write a Comment

Comment