How to Add a Whale of Plugins to Your Android App
- Author Kostya Kashyn
- Published April 23, 2019
- Word count 1,214
Is there a limit on how complex an android application can be? Most often, as a response, you can hear the opinion that such a restriction is the limitation of google play to the size of the added apk.
However, Multi-Programming Solutions has many popular applications, especially games, which have long overstepped this barrier and make no problems whatsoever. The point is that most of the space is occupied by resources (raster graphics, video and music), which are not necessary to be placed directly in the installation file (they can be placed in extension files or stored on their own servers, downloading as needed). Also if you want to have Log in function with Google, notifications and purchases, you should consider that you will meet the limitation in any way.
Can you imagine an Android game made in Unity that uses more than 64K Java methods? If your game exceeds the limit of 64K methods on a DEX file, you will have to poke around in your native plugins and / or build process. This post is an attempt to show different ways to solve the problem.
Understand your plugins
The most likely way to exceed this limit in Unity is to use native plugins. Native Android plugins are required in almost all Unity games. Unfortunately, some plugins are quite large. For example, Google Play Game Services itself contains almost 25K methods. This is a significant chunk of 64K that you are limited to.
Android Unity plugins usually consist of Unity C # code and native Android code and resources. Native code and resources are packaged either as an Android library project (Library Project), or as an Android Archive resource (AAR) in the Assets / Plugins / Android / directory. Project libraries are the old way to transfer components to the Android system, and AAR is a newer one. You will encounter plugins using both methods.
Classes in both project libraries and AAR exist in JAR files, which are simple zip files from compiled Java class files. The AAR file is also a simple zip of various Android resources. Some of them will become libs / *. Jar (also known as Java class archives). Library projects are simple directory structures, and the JAR, again, will be in libs / *. Jar.
Approaches of minimizing the number of methods
All the developers split up into two camps: those who still work with traditional approach and those who use new Unity features and mostly save their time. First, let’s take a look at the usual approaches of avoiding limitations.
Traditional
The way to reduce the number of Java methods contained in the game’s APK using the standard Unity build system is to delete or modify the JAR files included with the native Android plugins. An alternative way is to export the Unity project as an Android project, in which more powerful technologies can be applied.
Try each of the following techniques in turn:
• Remove all plugins that are not used by the game
Google has broken Play Services into a set of modules. Use only those that you really need.
Use the Jar Jar Links tool with the zap rule to remove unnecessary classes from JAR files of plugins.
• Export the project as an Android project to apply ProGuard or MultiDex
ProGuard is a tool used to obfuscate and remove unused classes and methods. MultiDex is a technology that allows you to use multiple DEX files in your APK, thus removing the limit of 64K methods in the game. Unity does not directly support these technologies, but you can use them by exporting a project as an Android project.
If nothing else helps, ProGuard can help lower the maximum limit. If this fails, use MultiDex. MultiDex has another limitation – it works only in API Level 14 (4.0) and higher. It is natively supported in Android (5.0) and higher. For versions 4.X you need to use support libraries. In addition, MultiDex has a list of known limitations.
If you need ProGuard or MultiDex, the first step is to export the Unity project as an Android project. If your project is complex enough, this in itself can be a daunting task. Most likely, it will also mean the unavailability of Unity Cloud Build.
However, with the right process, it may look like exporting to Xcode for iOS. After export, you need to set up an Android Studio or Gradle project, but this will be a one-time task. Re-exporting the project does not require new configuration of the Android assembly configuration.
The good side of this approach is that after setting up an Android Studio project, you can re-export a Unity project to the same directory. In this case, in general, an update of the Android Studio project is not required.
The bad side of this method is that the Android project will be associated with the files of the Android Studio project. Configuring dependencies will be challenging.
Renewed
Gradle is an Android build system which makes a number of build processes automatic. This feature implies that numerous basic mistakes are less inclined to happen. Most strikingly in Unity, it decreases the methods reference, included in DEX (Dalvik Executable configuration) documents, implying that you are more averse to go over DEX limit issues. However, because of the distinctions between Gradle and the default Unity Android build system, some current tasks might be difficult to change over toGradle.
You can either build the output (APK) utilizing the Gradle construct system in Unity, or fare the Gradle task and assemble it in an outside apparatus (for example, Android Studio).
The Gradle feature gives you extra option to export your Unity project into Android Studio one if the Export Project option is checked. This option must be checked when Gradle is selected. Gradle option is generally helpful for the Android platform only. It can configure such issues as:
• DEPS
• API VERSION
• BUILDTOOLS
• TARGETSDKVERSION
• APPLICATIONID
• MINIFY_DEBUG
• PROGUARD_DEBUG
• MINIFY_RELEASE
• PROGUARD_RELEASE
• USER_PROGUARD
• SIGN
• SIGN_CONFIG
• DIR_GRADLEPROJECT
• DIR_UNITYPROJECT
Another pro of Gradle is that it enables you to indicate your own gradle file to construct your Unity Project. Simply name the gradle file "mainTemplate.gradle" and place it in the AssetsPluginsAndroid directory.
Beforehand, to utilize gradle file in your project, you should trade the Unity Project as Android Project then utilize an outsider programming like Android Studio or Eclipse to add gradle backing to your application. But now it is made that simpler. With upgrading Unity to version 5.5, you can now use Gradle to build for Android. Gradle is not as strict about errors compared with the existing Unity Android build system, meaning that some existing projects may be hard to convert to Gradle.
You would now be able to do that without sending out the project at all. It will save your time while building an app and give you an opportunity to add as many apks as you need.
Conclusion
Building a complex Android app is a project which needs a professional view and a pack of experience. There were the best approaches to reduce the APK and, fortunately, now you have a better knowledge how to solve the most common Android problem. Multi-Programming Solutions deals with such issues daily and open to new ideas and tasks.
Contact us to get the consultation
https://multi-programming.com/how-to-add-a-whale-of-plugins-to-your-android-app
Software Development for Your Company's Growth
Article source: https://art.xingliano.comRate article
Article comments
There are no posted comments.
Related articles
- Minimalist or Statement Sliding Barn Door: Which Is Right for Your Space
- How to Style Antique Indian Armoires & Sideboards in a Modern Home
- Custom Antique Doors: How Mogul Interior Sizes Vintage Doors to Fit Any Space
- Personalized Dining Experiences: How AI POS Systems Learn Your Customers’ Preferences
- Perth Is One of Australia's Fastest Growing Cities. Here Is What That Looks Like on the Ground
- Ireland–China Relations: A Century Built on Exchange and Understanding
- Mindfulness: Living in Harmony with the Elements
- Lash Extension Aftercare Starts With Proper Removal
- How Lash Techs Can Make Removal Appointments More Comfortable
- Electric And Hybrid Car Leasing: The Smart Move For 2026
- What Clients Should Know Before a Lash Extension Removal Appointment
- Common Lash Removal Mistakes New Lash Techs Should Avoid
- Lash Remover Cream vs. Liquid Remover: What Lash Techs Should Know
- Common Lash Removal Mistakes New Lash Techs Should Avoid
- Lash Remover Cream vs. Liquid Remover: What Lash Techs Should Know
- Common Eyebrow Tint Mistakes and How to Avoid Them
- Outdoor Makeup Tips for Hot Days: What to Keep Simple Around the Eyes
- How to Choose the Right Brow Tint Shade for a Natural Look
- Best Eye Makeup Ideas for Summer Travel and Weekend Trips
- Magnetic Lashes vs. Strip Lashes: Which Is Easier for Beginners?
- Lotus Carved Decorative Doors
- Where Your Donation Matters Most: Helping the Poor with Medical Care and Animal Welfare in India
- Solutions For Clinical Trials
- How Sponsoring Elderly Care in India Creates Lasting Social Impact
- Motorcycle Accidents in Hattiesburg: Mississippi's Pure Comparative Fault Advantage and How It Protects Injured Riders
- Dog Bite Injuries in Colorado: How the Strict Liability Statute Works and What Injured Victims Can Recover
- Truck Accident Claims in Green Bay: How Local Industries Shape Liability
- Dog Bites in San Luis Obispo: California's Strict Liability & What It Means for Victims
- How the Region's Paper and Food Processing Industries Shape the Commercial Vehicle Liability Landscape
- Colorado Dog Bite Injury Claims and What the State's Strict Liability Law Means for Victims