How to Deal with the Issue of Android DEX 64K Methods Limit?



Resolve Android 64K Methods Issue

Android has a constraint of 64K method limit. Since game will include 3rd party libraries (including KTplay SDK) that will have chance of adding up all method size will exceed the limit, there are numbers of approach can mitigate the issues.

1. Excludes unnecessary modules from 3rd party libraries.

Some 3rd party libraries such as Google Play Services provide lot fo features, but only part of them are used by game, then you need to exclude unnecessary modules if possible.

  • Only include required modules instead of all of them if possible. e.g. for Google Play Services, you can include individual module through the instruments listed here.
  • Use lighter version of libraries if possible, e.g. for Google Play Services, try to use Google Play game Services SDK

2. Use ProGuard to shrink the unused classes and methods.

  • Code shrinking is available with ProGuard, which detects and removes unused classes, fields, methods, and attributes from your packaged app. please following the instruments from Google's documetation
  • For some situations, You need to force ProGuard to keep certain code such as reflection and JNI code, (The chapter "Customize which code to keep" from Google's documnetation, The code need to keep by KTplay is listed below, please append it to your ProGuard rules file (
-keep public class
-keep public class{*;}
-keep public class$**{*;}
-keep public class*{*;}
-keep public class * extends com.kryptanium.plugin.KTPlugin{
   public <methods>;
   public <fields>;
-keep public class{*;}
-keep public class$Info{*;}
  • Unity Project

    Since ProGuard cannot be used in Unity, you need to export the app project to Android Studio before use it, here is the steps required

    • Remove KTPlay Android Plugin from Unity project

      • Locate the folder (Assets/Plugins/Android/KTplay)
      • Move the folder to somewhere safe as it will be needed later.
      • Remove all .meta files from the folder (KTplay)
    • Export the app project to Android Studio

      • In Unity, select File - Android - Google Android Project - Export to export the app project
      • In Android Studio, select File - New - Import Project to import the app project exported
    • Import KTPlay Android Plugin back to Android Studio

      • In Android Studio, select File - New - Import Module to import project from the folder contain the moved KTplay Android Plugin from 1st step above
      • Add KTPlay project dependencies 。
        Open app project's build.gradle,and add the following to dependencies:

        compile project(':KTPlay')
Have more questions? Submit a request


Please sign in to leave a comment.