1. Are you ready for the Galaxy S20? Here is everything we know so far!

65k Limitation and how-to MultiDex?

Discussion in 'Android Development' started by ac4android, Mar 8, 2016.

  1. ac4android

    ac4android Well-Known Member
    Thread Starter


    On building the gradle to run the app, I am starting to log a lot of errors. After commenting out downstream Intent(someactivity, some.class), I was able to narrow it down to what seems to be caused by a 65k limitation. But I'm still getting the dalvik-error! The codes can only grow further.

    How do I move forward?

    UPDATE: the AVD complains about running out of space and the app might not load, but then the app does run !?!

    E/Trace: error opening trace file: No such file or directory (2)
    E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.zze.zzb

    Updated my build.gradle with MultiDex
    apply plugin: 'com.android.application'
    android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
    applicationId "com.myproject.android101"
    minSdkVersion 17
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"

    multiDexEnabled true

    buildTypes {
    release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.android.support:design:23.2.0'
    compile 'com.android.support:support-v4:23.2.0'
    compile 'com.google.android.gms:play-services-plus:8.4.0'
    compile 'com.google.android.gms:play-services:8.4.0'
    compile 'com.google.android.gms:play-services-maps:8.4.0'
    compile 'com.google.android.gms:play-services-ads:8.4.0'
    compile 'com.google.android.gms:play-services-identity:8.4.0'
    compile 'com.google.android.gms:play-services-gcm:8.4.0'
    compile 'com.google.android.gms:play-services-analytics:8.4.0'

    compile 'com.android.support:multidex:1.0.1'


    Inserted MultiDex into my AndroidManifest
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"

    lots of XML

    android:name="android.support.multidex.MultiDexApplication" >

    Inserted into MainActivity.class
    Code (Text):
    2. public class TopLevelActivity extends Activity {
    4.     [USER=1021285]@override[/USER]
    5.     protected void onCreate(Bundle savedInstanceState) {
    6.         super.onCreate(savedInstanceState);
    7.         setContentView(R.layout.activity_top_level);
    8.         // We need an OnItemClickListener for the array options in top level XML
    9.         AdapterView.OnItemClickListener itemClickListener = new AdapterView.OnItemClickListener(){
    10.             // we have to create the onItemClick method ourself
    11.             public void onItemClick(AdapterView<?> listView,
    12.                                     View v,
    13.                                     int position,
    14.                                     long id) {
    15.                 if (position == 0) {
    16.                     Intent intent = new Intent(TopLevelActivity.this, SomeActivity.class);
    17.                     startActivity(intent);
    18.                 }
    19.             }
    20.         };
    21.         // Instantiate a list view to display the list options using the layout in the XML file
    22.         ListView listView = (ListView) findViewById(R.id.list_options);
    23.         // ...then plug the listener into the list view
    24.         listView.setOnItemClickListener(itemClickListener);
    25.     }
    26.     // Use multidex to overcome the 65k limit, NB will only work with version# > 14
    27.     public void attachBaseContext(Context newBase) {
    28.         super.attachBaseContext(newBase);
    29.         MultiDex.install(this);
    30.     }
    32. }

    #1 ac4android, Mar 8, 2016
    Last edited: Mar 8, 2016
  2. Brinkkemper

    Brinkkemper Lurker

    remove this line:

    compile 'com.google.android.gms:play-services:8.4.0'
    (this compiles ALL services into your project. only use the parts you need.)

    also, put multiDexEnabled back to false ;) You really don't want to use it

    and do a "clean project".
    and your good to go
    ac4android likes this.

Share This Page