When your application and the libraries it references reach a certain size (65k or more), you encounter build errors that indicate your app has reached a limit of the Android app build architecture. Find more information on this error here. Here are some steps that you can follow to overcome this:
- Check for unwanted jars in your project and remove that to reduce method count. (Strongly recommended)
- Export your unity project to google android project. (If step 1 does not work)
Steps to export a project to Android Studio
- Open Build Settings.
- Select the Google Android Project checkbox.
- Click Export to export the unity project into Android.
- Unity will build the project, export it to android, and store the android project on your specified path.
Here, VMAX_Unty_Ad_Sample is unity project name, other folders are library projects folders used on unity side.
- Open Android Studio and select New >> Import Project.
- Set the file path to exported android project.
- Once it’s imported, you will see that all the library projects will also get imported to Android Studio and the final studio project structure will look like this.
- Open the file build.gradle in your project.
- Add this part to the android section:
1234dexOptions {incremental truejavaMaxHeapSize "4g"} - Also add this line to the defaultConfig section:
1multiDexEnabled true - Add this line under the dependencies section:
1compile 'com.android.support:multidex:1.0.1' - Finally, clean the project. The final build.gradle file will look similar to this:
- Open AndroidManifest.xml file and in <application> tag write this line.
1android:name="android.support.multidex.MultiDexApplication" - Copy the library (.jar) files to your application’s libs folder and add this line in the dependencies tag of build.gradle:
1compile fileTree(dir: 'libs', include: ['*.jar']) - If the library folder has assets (like resource/drawable/asset), then you have to add that library as module in Android Studio.
Select the module you want to add to project.
- You also need to add the module to your project dependency.