Skip to main content
Giving proper credit.
Source Link
Vaillancourt
  • 16.4k
  • 17
  • 56
  • 61

This answer relies heavily on Android's official documentation (the quoted parts, specifically).


How to setup Multidex Support for Unity Project

What is Multidex: Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multi dex configuration.

Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multi dex configuration.

When we exceed the total number of methods that can be referenced within a single DEX file to 65,536- including Android framework methods, library methods and methods in your own code. Avoid the 64K limit: Before configuring your app to enable the use of 64k or more method references, you should take steps to reduce the total number of references called by your app code, including methods defined by your app code or including libraries.

The following steps will help you to avoid or reduce this issue, keep patience.

Avoid the 64K limit

Step 1: Build an Android Project from your Unity Editor. Setp 1

Before configuring your app to enable use of 64K or more method references, you should take steps to reduce the total number of references called by your app code, including methods defined by your app code or included libraries. The following strategies can help you avoid hitting the DEX reference limit:

Step 2: Import your Android Project in Android Studio.

Review your app's direct and transitive dependencies - Ensure any large library dependency you include in your app is used in a manner that outweighs the amount of code being added to the app. A common anti-pattern is to include a very large library because a few utility methods were useful. Reducing your app code dependencies can often help you avoid the DEX reference limit.

Step 2

Remove unused code with ProGuard - Enable code shrinking to run ProGuard for your release builds. Enabling shrinking ensures you are not shipping unused code with your APKs.

Step 3: Setting up Aside from these official tips, when building your appUnity project to use a multi dex configuration requires that your make the following modification. For minSdkVersion >= 21 All you need to do is set multiDexEnabled to true in the Main-Project build.Gradle file: Step3 For minSdkVersion is <=20, then you must use the multi dex support library as follows: Modify the Main_Project build.Gradle file to enable multi dex and add the multi dex library as a dependency: step 3.1

Step 4: If you override the Application class, perform one of the following: If you do not override the Application class, edit your Main manifest file to set android: name in the tag as follows:

Step 4 Paste these entries in your java class:

package com.DemoProj.DemoApplication;
import android.app.Application;
import android.support.multidex.MultiDexApplication;

public class DemoApplication extends MultiDexApplication {

    public DemoApplication() {
        try {
        } catch (Exception e) {
        }
    }
}

Now add the class in your Main manifest: Add android:name=".your Java class name" and now add android:allowBackup = "true" inside your main manifest application tag. Step 4.1

Step 5: Check error form other plugins manifest and clean the project.And sysc again.

Step 6: If there is any dependency issue is still there in your project run this command in Android Terminal Gradle clean App."App name" and press enter.

Step 7: Copy these dependency in your Application Gradle , under dependencies: compile fileTree(include: ['.jar'], dir: 'bin') compile fileTree(include: ['.jar'], dirsteps will help you further: 'libs')

Step 8: Add the signingConfig in your main projects Gradle. Step 8 Or set the Signing mode to Debug mode by manually, Go to File-> Project Structure -> Under Modules Click on your project and under Build Types select Debug ->choose Signing Config-> debug enter image description here

Now sync your Gradle and build the project.

  1. Build an Android Project from your Unity Editor. Setp 1

  2. Import your Android Project in Android Studio. Step 2

  3. Setting up your app project to use a multi dex configuration requires that your make the following modification.

    If your minSdkVersion is set to 21 or higher, all you need to do is set multiDexEnabled to true in your module-level build.gradle file, as shown here:

     android {
     defaultConfig {
             ...
             minSdkVersion 21 
             targetSdkVersion 26
             multiDexEnabled true
         }
         ...
     }
    

    However, if your minSdkVersion is set to 20 or lower, then you must use the multidex support library as follows:

    3.1. Modify the module-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here:

     android {
         defaultConfig {
             ...
             minSdkVersion 15 
             targetSdkVersion 26
             multiDexEnabled true
         }
         ...
     }
    
     dependencies {
       compile 'com.android.support:multidex:1.0.1'
     }
    

    3.2. Depending on whether you override the Application class, perform one of the following:

    • If you do not override the Application class, edit your manifest file to set android:name in the <application> tag as follows:
     <?xml version="1.0" encoding="utf-8"?>
     <manifest xmlns:android="http://schemas.android.com/apk/res/android"
         package="com.example.myapp">
         <application
                 android:name="android.support.multidex.MultiDexApplication" >
             ...
         </application>
     </manifest>
    
    • If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows:
     public class MyApplication extends MultiDexApplication { ... }
    
    • Or if you do override the Application class but it's not possible to change the base class, then you can instead override the attachBaseContext() method and call MultiDex.install(this) to enable multidex:
     public class MyApplication extends SomeOtherApplication {
       @Override
       protected void attachBaseContext(Context base) {
          super.attachBaseContext(base);
          MultiDex.install(this);
       }
     }
    
  4. Check error form other plugins manifest and clean the project.And sysc again.

  5. If there is any dependency issue in your project, run this command in Android Terminal

     % Gradle clean App."App name"
    
  6. Copy these dependency in your Application Gradle , under dependencies:

     compile fileTree(include: ['*.jar'], dir: 'bin')
     compile fileTree(include: ['*.jar'], dir: 'libs')
    
  7. Add the signingConfig in your main projects Gradle.

    Step 8

    Or set the Signing mode to Debug mode by manually, Go to File -> Project Structure -> Under Modules Click on your project and under Build Types select Debug ->choose Signing Config-> debug

    enter image description here

  8. Now sync your Gradle and build the project.

How to setup Multidex Support for Unity Project

What is Multidex: Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multi dex configuration.

When we exceed the total number of methods that can be referenced within a single DEX file to 65,536- including Android framework methods, library methods and methods in your own code. Avoid the 64K limit: Before configuring your app to enable the use of 64k or more method references, you should take steps to reduce the total number of references called by your app code, including methods defined by your app code or including libraries.

The following steps will help you to avoid or reduce this issue, keep patience.

Step 1: Build an Android Project from your Unity Editor. Setp 1

Step 2: Import your Android Project in Android Studio.

Step 2

Step 3: Setting up your app project to use a multi dex configuration requires that your make the following modification. For minSdkVersion >= 21 All you need to do is set multiDexEnabled to true in the Main-Project build.Gradle file: Step3 For minSdkVersion is <=20, then you must use the multi dex support library as follows: Modify the Main_Project build.Gradle file to enable multi dex and add the multi dex library as a dependency: step 3.1

Step 4: If you override the Application class, perform one of the following: If you do not override the Application class, edit your Main manifest file to set android: name in the tag as follows:

Step 4 Paste these entries in your java class:

package com.DemoProj.DemoApplication;
import android.app.Application;
import android.support.multidex.MultiDexApplication;

public class DemoApplication extends MultiDexApplication {

    public DemoApplication() {
        try {
        } catch (Exception e) {
        }
    }
}

Now add the class in your Main manifest: Add android:name=".your Java class name" and now add android:allowBackup = "true" inside your main manifest application tag. Step 4.1

Step 5: Check error form other plugins manifest and clean the project.And sysc again.

Step 6: If there is any dependency issue is still there in your project run this command in Android Terminal Gradle clean App."App name" and press enter.

Step 7: Copy these dependency in your Application Gradle , under dependencies: compile fileTree(include: ['.jar'], dir: 'bin') compile fileTree(include: ['.jar'], dir: 'libs')

Step 8: Add the signingConfig in your main projects Gradle. Step 8 Or set the Signing mode to Debug mode by manually, Go to File-> Project Structure -> Under Modules Click on your project and under Build Types select Debug ->choose Signing Config-> debug enter image description here

Now sync your Gradle and build the project.

This answer relies heavily on Android's official documentation (the quoted parts, specifically).


How to setup Multidex Support for Unity Project

What is Multidex:

Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multi dex configuration.

When we exceed the total number of methods that can be referenced within a single DEX file to 65,536- including Android framework methods, library methods and methods in your own code.

Avoid the 64K limit

Before configuring your app to enable use of 64K or more method references, you should take steps to reduce the total number of references called by your app code, including methods defined by your app code or included libraries. The following strategies can help you avoid hitting the DEX reference limit:

Review your app's direct and transitive dependencies - Ensure any large library dependency you include in your app is used in a manner that outweighs the amount of code being added to the app. A common anti-pattern is to include a very large library because a few utility methods were useful. Reducing your app code dependencies can often help you avoid the DEX reference limit.

Remove unused code with ProGuard - Enable code shrinking to run ProGuard for your release builds. Enabling shrinking ensures you are not shipping unused code with your APKs.

Aside from these official tips, when building your Unity project, following these steps will help you further:

  1. Build an Android Project from your Unity Editor. Setp 1

  2. Import your Android Project in Android Studio. Step 2

  3. Setting up your app project to use a multi dex configuration requires that your make the following modification.

    If your minSdkVersion is set to 21 or higher, all you need to do is set multiDexEnabled to true in your module-level build.gradle file, as shown here:

     android {
     defaultConfig {
             ...
             minSdkVersion 21 
             targetSdkVersion 26
             multiDexEnabled true
         }
         ...
     }
    

    However, if your minSdkVersion is set to 20 or lower, then you must use the multidex support library as follows:

    3.1. Modify the module-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here:

     android {
         defaultConfig {
             ...
             minSdkVersion 15 
             targetSdkVersion 26
             multiDexEnabled true
         }
         ...
     }
    
     dependencies {
       compile 'com.android.support:multidex:1.0.1'
     }
    

    3.2. Depending on whether you override the Application class, perform one of the following:

    • If you do not override the Application class, edit your manifest file to set android:name in the <application> tag as follows:
     <?xml version="1.0" encoding="utf-8"?>
     <manifest xmlns:android="http://schemas.android.com/apk/res/android"
         package="com.example.myapp">
         <application
                 android:name="android.support.multidex.MultiDexApplication" >
             ...
         </application>
     </manifest>
    
    • If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows:
     public class MyApplication extends MultiDexApplication { ... }
    
    • Or if you do override the Application class but it's not possible to change the base class, then you can instead override the attachBaseContext() method and call MultiDex.install(this) to enable multidex:
     public class MyApplication extends SomeOtherApplication {
       @Override
       protected void attachBaseContext(Context base) {
          super.attachBaseContext(base);
          MultiDex.install(this);
       }
     }
    
  4. Check error form other plugins manifest and clean the project.And sysc again.

  5. If there is any dependency issue in your project, run this command in Android Terminal

     % Gradle clean App."App name"
    
  6. Copy these dependency in your Application Gradle , under dependencies:

     compile fileTree(include: ['*.jar'], dir: 'bin')
     compile fileTree(include: ['*.jar'], dir: 'libs')
    
  7. Add the signingConfig in your main projects Gradle.

    Step 8

    Or set the Signing mode to Debug mode by manually, Go to File -> Project Structure -> Under Modules Click on your project and under Build Types select Debug ->choose Signing Config-> debug

    enter image description here

  8. Now sync your Gradle and build the project.

Step 4 Paste these entries in your java class: package com.DemoProj.DemoApplication; import android.app.Application; import android.support.multidex.MultiDexApplication;

public class DemoApplication extends MultiDexApplication {

package com.DemoProj.DemoApplication;
import android.app.Application;
import android.support.multidex.MultiDexApplication;

public class DemoApplication extends MultiDexApplication {

    public DemoApplication() {
        try {
        } catch (Exception e) {
        }
    }
}

}

Now add the class in your Main manifest: Add android:name=".your Java class name"android:name=".your Java class name" and now add android:allowBackup = "true"android:allowBackup = "true" inside your main manifest application tag. Step 4.1

Step 4 Paste these entries in your java class: package com.DemoProj.DemoApplication; import android.app.Application; import android.support.multidex.MultiDexApplication;

public class DemoApplication extends MultiDexApplication {

public DemoApplication() {
    try {
    } catch (Exception e) {
    }
}

}

Now add the class in your Main manifest: Add android:name=".your Java class name" and now add android:allowBackup = "true" inside your main manifest application tag. Step 4.1

Step 4 Paste these entries in your java class:

package com.DemoProj.DemoApplication;
import android.app.Application;
import android.support.multidex.MultiDexApplication;

public class DemoApplication extends MultiDexApplication {

    public DemoApplication() {
        try {
        } catch (Exception e) {
        }
    }
}

Now add the class in your Main manifest: Add android:name=".your Java class name" and now add android:allowBackup = "true" inside your main manifest application tag. Step 4.1

added 4 characters in body
Source Link
Rakesh
  • 539
  • 3
  • 14

How to setup Multidex Support for Unity Project

What is Multidex:What is Multidex: Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multi dex configuration.

When we use Multidex:

When we exceed the total number of methods that can be referenced within a single DEX file to 65,536- including Android framework methods, library methods and methods in your own code. Avoid the 64K limit: Before configuring your app to enable the use of 64k or more method references, you should take steps to reduce the total number of references called by your app code, including methods defined by your app code or including libraries.

The following steps will help you to avoid or reduce this issue, keep patience.

Step 1: Build an Android Project from your Unity Editor. Setp 1

Step 2: Import your Android Project in Android Studio.

Step 2Step 2

Step 3: Setting up your app project to use a multi dex configuration requires that your make the following modification. For minSdkVersion >= 21 All you need to do is set multiDexEnabled to true in the Main-Project build.Gradle file: Step3 For minSdkVersion is <=20, then you must use the multi dex support library as follows: Modify the Main_Project build.Gradle file to enable multi dex and add the multi dex library as a dependency: step 3.1

Step 4: If you override the Application class, perform one of the following: If you do not override the Application class, edit your Main manifest file to set android: name in the tag as follows:

Step 4 Paste these entries in your java class: package com.DemoProj.DemoApplication; import android.app.Application; import android.support.multidex.MultiDexApplication;

public class DemoApplication extends MultiDexApplication {

public DemoApplication() {
    try {
    } catch (Exception e) {
    }
}

}

Now add the class in your Main manifest: Add android:name=".your Java class name" and now add android:allowBackup = "true" inside your main manifest application tag. Step 4.1

Step 5: Check error form other plugins manifest and clean the project.And sysc again.

Step 6: If there is any dependency issue is still there in your project run this command in Android Terminal Gradle clean App."App name" and press enter.

Step 7: Copy these dependency in your Application Gradle , under dependencies: compile fileTree(include: ['.jar'], dir: 'bin') compile fileTree(include: ['.jar'], dir: 'libs')

Step 8: Add the signingConfig in your main projects Gradle. Step 8 Or set the Signing mode to Debug mode by manually, Go to File-> Project Structure -> Under Modules Click on your project and under Build Types select Debug ->choose Signing Config-> debug enter image description here

Now sync your Gradle and build the project.

How to setup Multidex Support for Unity Project

What is Multidex: Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multi dex configuration.

When we use Multidex:

When we exceed the total number of methods that can be referenced within a single DEX file to 65,536- including Android framework methods, library methods and methods in your own code. Avoid the 64K limit: Before configuring your app to enable the use of 64k or more method references, you should take steps to reduce the total number of references called by your app code, including methods defined by your app code or including libraries.

The following steps will help you to avoid or reduce this issue, keep patience.

Step 1: Build an Android Project from your Unity Editor. Setp 1

Step 2: Import your Android Project in Android Studio.

Step 2

Step 3: Setting up your app project to use a multi dex configuration requires that your make the following modification. For minSdkVersion >= 21 All you need to do is set multiDexEnabled to true in the Main-Project build.Gradle file: Step3 For minSdkVersion is <=20, then you must use the multi dex support library as follows: Modify the Main_Project build.Gradle file to enable multi dex and add the multi dex library as a dependency: step 3.1

Step 4: If you override the Application class, perform one of the following: If you do not override the Application class, edit your Main manifest file to set android: name in the tag as follows:

Step 4 Paste these entries in your java class: package com.DemoProj.DemoApplication; import android.app.Application; import android.support.multidex.MultiDexApplication;

public class DemoApplication extends MultiDexApplication {

public DemoApplication() {
    try {
    } catch (Exception e) {
    }
}

}

Now add the class in your Main manifest: Add android:name=".your Java class name" and now add android:allowBackup = "true" inside your main manifest application tag. Step 4.1

Step 5: Check error form other plugins manifest and clean the project.And sysc again.

Step 6: If there is any dependency issue is still there in your project run this command in Android Terminal Gradle clean App."App name" and press enter.

Step 7: Copy these dependency in your Application Gradle , under dependencies: compile fileTree(include: ['.jar'], dir: 'bin') compile fileTree(include: ['.jar'], dir: 'libs')

Step 8: Add the signingConfig in your main projects Gradle. Step 8 Or set the Signing mode to Debug mode by manually, Go to File-> Project Structure -> Under Modules Click on your project and under Build Types select Debug ->choose Signing Config-> debug enter image description here

Now sync your Gradle and build the project.

How to setup Multidex Support for Unity Project

What is Multidex: Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multi dex configuration.

When we use Multidex:

When we exceed the total number of methods that can be referenced within a single DEX file to 65,536- including Android framework methods, library methods and methods in your own code. Avoid the 64K limit: Before configuring your app to enable the use of 64k or more method references, you should take steps to reduce the total number of references called by your app code, including methods defined by your app code or including libraries.

The following steps will help you to avoid or reduce this issue, keep patience.

Step 1: Build an Android Project from your Unity Editor. Setp 1

Step 2: Import your Android Project in Android Studio.

Step 2

Step 3: Setting up your app project to use a multi dex configuration requires that your make the following modification. For minSdkVersion >= 21 All you need to do is set multiDexEnabled to true in the Main-Project build.Gradle file: Step3 For minSdkVersion is <=20, then you must use the multi dex support library as follows: Modify the Main_Project build.Gradle file to enable multi dex and add the multi dex library as a dependency: step 3.1

Step 4: If you override the Application class, perform one of the following: If you do not override the Application class, edit your Main manifest file to set android: name in the tag as follows:

Step 4 Paste these entries in your java class: package com.DemoProj.DemoApplication; import android.app.Application; import android.support.multidex.MultiDexApplication;

public class DemoApplication extends MultiDexApplication {

public DemoApplication() {
    try {
    } catch (Exception e) {
    }
}

}

Now add the class in your Main manifest: Add android:name=".your Java class name" and now add android:allowBackup = "true" inside your main manifest application tag. Step 4.1

Step 5: Check error form other plugins manifest and clean the project.And sysc again.

Step 6: If there is any dependency issue is still there in your project run this command in Android Terminal Gradle clean App."App name" and press enter.

Step 7: Copy these dependency in your Application Gradle , under dependencies: compile fileTree(include: ['.jar'], dir: 'bin') compile fileTree(include: ['.jar'], dir: 'libs')

Step 8: Add the signingConfig in your main projects Gradle. Step 8 Or set the Signing mode to Debug mode by manually, Go to File-> Project Structure -> Under Modules Click on your project and under Build Types select Debug ->choose Signing Config-> debug enter image description here

Now sync your Gradle and build the project.

Source Link
Rakesh
  • 539
  • 3
  • 14
Loading