title: MultiDex stopped working Android
body: <p>last night I was working on my app, initially I already reached my 64k limit so have had multidex for sometime now, sometimes it does fail and gives me a <code>ClassNotFoundException</code> but all I do is recompile my code and it works, if it fails I restart my computer but this time it is a different case, MultiDex seems to be excluding one of my classes which is funny because it was working until it suddenly stop, what it is doing it is excluding my <code>EnhancedGallery.class</code> which am using as my start activity, if I change to some other activity as start activity in manifest the App works until I try to run <code>EnhancedGallery</code> below are my Gradle Configurations </p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  
  android {
  compileSdkVersion 23
  buildToolsVersion "23.0.1"
  defaultConfig {
      applicationId "aubry.chromio.com.dressup"
      minSdkVersion 15
      targetSdkVersion 23
      versionCode 1
      versionName "1.0"
  
  }
  buildTypes {
      release {
          minifyEnabled false
          proguardFiles getDefaultProguardFile('proguard-android.txt'),    'proguard-rules.pro'
      }
    }
     productFlavors {
     }
     sourceSets { main { res.srcDirs = ['src/main/res', '  src/main/res/layout_land'] } }
  
  
  
  dexOptions {
      preDexLibraries = false
      javaMaxHeapSize "2g"
  }
  
  afterEvaluate {
      tasks.matching {
          it.name.startsWith('dex')
      }.each { dx -&gt;
          if (dx.additionalParameters == null) {
              dx.additionalParameters = []
          }
          dx.additionalParameters += '--multi-dex'
          // dx.additionalParameters += "--main-dex-    list=$projectDir/dexFiles".toString()
      }
  }
   }
  
  
  dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile('com.twitter.sdk.android:twitter:1.6.0@aar') {
      transitive = true;
  }
  compile 'com.android.support:appcompat-v7:23.1.0'
  compile 'com.android.support:design:23.1.0'
  compile 'com.commit451:PhotoView:1.2.4'
  compile 'com.google.android.gms:play-services:8.1.0'
  compile 'com.wang.avi:library:1.0.0'
  compile 'com.nineoldandroids:library:2.4.0'
  compile 'com.google.android.gms:play-services-gcm:8.1.0'
  compile 'com.facebook.android:facebook-android-sdk:4.5.0'
  compile 'com.commonsware.cwac:camera:0.6.+'
  compile project(':android-support-multidex')
  compile 'com.android.support:support-v13:23.1.0'
  compile 'com.android.support:palette-v7:23.1.0'
  compile 'com.android.support:cardview-v7:23.1.0'
  compile 'com.github.ozodrukh:CircularReveal:1.1.0'
  compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
  compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
  
   }
  </code></pre>
  
  <p>My <strong>App.class</strong> where I give gradle my app Context </p>
  
  <pre><code>import android.app.Application;
  import android.content.Context;
  import android.support.multidex.MultiDex;
  
  
   public class App extends Application {
   private static App instance;
  
   @Override public void onCreate() {
   super.onCreate();
   instance = this;
  
  }
  
  @Override
  protected void attachBaseContext(Context base) {
      super.attachBaseContext(base);
      MultiDex.install(this);
  }
  
   public static App get() {
   return instance;
  }
  
  
  }
  </code></pre>
  
  <p>My Middle level Gradle file:</p>
  
  <pre><code>configurations.create("default")
  artifacts.add("default", file('android-support-multidex.jar'))
  </code></pre>
  
  <p>And My top Level Gradle File:</p>
  
  <pre><code>// Top-level build file where you can add configuration options common to all sub-projects/modules.
  
    buildscript {
     repositories {
      jcenter()
      mavenCentral()
      maven { url 'https://maven.fabric.io/public' }
  
  
     }
     dependencies {
      classpath 'com.android.tools.build:gradle:1.3.0'
      // NOTE: Do not place your application dependencies here; they belong
      // in the individual module build.gradle files
  
      // The Fabric Gradle plugin uses an open ended version to
      // react quickly to Android tooling updates
      classpath 'io.fabric.tools:gradle:1.+'
    }
  }
  
   allprojects {
    repositories {
      jcenter()
      maven {
          url 'https://maven.fabric.io/public'
      }
  
      maven {
          url "https://s3.amazonaws.com/repo.commonsware.com"
      }
      maven {
          url 'http://dl.bintray.com/amulyakhare/maven'
      }
      maven {
          url "https://jitpack.io"
      }
  
    }
   }
  
   task clean(type: Delete) {
   delete rootProject.buildDir
  }
  </code></pre>
  
  <p><strong>My error Report:</strong></p>
  
  <pre><code>1-14 09:25:49.430 30154-30154/aubry.chromio.com.dressup E/dalvikvm:  
  Could not    find class 'android.support.v4.app.
  NotificationCompat$Builder',  referenced from method     
  com.google.android.gms.common.GooglePlayServicesUtil.zza
  11-14 09:25:49.431 30154-30154/aubry.chromio.com.dressup
  E/dalvikvm: Could not find class 'android.support.v4.app.FragmentActivity',   
  referenced from method  
  com.google.android.gms.common.GooglePlayServicesUtil.zza
  11-14 09:25:49.432 30154-30154/aubry.chromio.com.dressup E/dalvikvm: Could not  
  find class 'android.support.v4.app.FragmentActivity', referenced from method    
  com.google.android.gms.common.GooglePlayServicesUtil.zza
  11-14 09:25:49.442 30154-30154/aubry.chromio.com.dressup E/dalvikvm: Could not  
  find class 'android.app.AppOpsManager', referenced from method  
  com.google.android.gms.common.GooglePlayServicesUtil.zzb
  11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:  
  FATAL EXCEPTION: main
  11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:  
  java.lang.RuntimeException: Unable to instantiate activity  
  
  ComponentInfo{aubry.chromio.com.dressup/aubry.chromio.com.dressup.activities.Enhan    cedGallery}: java.lang.ClassNotFoundException: Didn't find class  
  "aubry.chromio.com.dressup.activities.EnhancedGallery" on path:  
   DexPathList[[zip file "/data/app/aubry.chromio.com.dressup- 
   1.apk"],nativeLibraryDirectories=[/data/app-lib/aubry.chromio.com.dressup-1,  
   /vendor/lib, /system/lib]]
   11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:       
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
   11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:      
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
   11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:      
   at android.app.ActivityThread.access$600(ActivityThread.java:162)
   11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:      
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
   11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:      
   at android.os.Handler.dispatchMessage(Handler.java:107)
   11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:      
   at android.os.Looper.loop(Looper.java:194)
   11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:     
   at android.app.ActivityThread.main(ActivityThread.java:5371)
   11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:     
   at java.lang.reflect.Method.invokeNative(Native Method)
   11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:     
   at java.lang.reflect.Method.invoke(Method.java:525)
   11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:       
   at    
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
   11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
  11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:       
  at dalvik.system.NativeStart.main(Native Method)
  11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:  
  Caused by: java.lang.ClassNotFoundException: Didn't find class    
  "aubry.chromio.com.dressup.activities.EnhancedGallery" on path:   
   DexPathList[[zip file "/data/app/aubry.chromio.com.dressup-  
  1.apk"],nativeLibraryDirectories=[/data/app-lib/aubry.chromio.com.dressup-1,  
  /vendor/lib, /system/lib]]
  11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:      
  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
  </code></pre>
  
  <p>And lastly my <strong>EnhancedGallery Class</strong> </p>
  
  <pre><code>import android.content.Context;
  import android.database.Cursor;
  import android.graphics.Point;
  import android.net.Uri;
  import android.os.Bundle;
  import android.provider.MediaStore;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.Display;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.FrameLayout;
  import android.widget.GridView;
  import android.widget.ImageView;
  
  import java.util.HashSet;
  import java.util.Set;
  
  import #####.chromio.com.#####.R;
  import #####.chromio.com.#####.polypicker.model.Image;
  import #####.chromio.com.#####.polypicker.utils.ImageInternalFetcher;
  
   public class EnhancedGallery extends AppCompatActivity implements     
   View.OnScrollChangeListener{
   public ImageInternalFetcher mImageFetcher;
    private ImageGalleryAdapter mGalleryAdapter;
    private Set&lt;Image&gt; mSelectedImages;
    Display display;
  
  Toolbar toolbar;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_enhanced_gallery);
      toolbar = (Toolbar) findViewById(R.id.toolbar_transparent);
      setSupportActionBar(toolbar);
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      mGalleryAdapter = new ImageGalleryAdapter(this);
      GridView galleryGridView = (GridView)findViewById(R.id.pp__gallery_grid);
      mSelectedImages = new HashSet&lt;Image&gt;();
      mImageFetcher = new ImageInternalFetcher(this, 500);
  
      Cursor imageCursor = null;
      try {
          final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.ImageColumns.ORIENTATION};
          final String orderBy = MediaStore.Images.Media.DATE_ADDED + " DESC";
          imageCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null, null, orderBy);
          while (imageCursor.moveToNext()) {
              Uri uri = Uri.parse(imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA)));
              int orientation = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION));
              mGalleryAdapter.add(new Image(uri, orientation));
          }
      } catch (Exception e) {
          e.printStackTrace();
      } finally {
          if(imageCursor != null &amp;&amp; !imageCursor.isClosed()) {
              imageCursor.close();
          }
      }
  
  
      galleryGridView.setAdapter(mGalleryAdapter);
      galleryGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
              Image image = mGalleryAdapter.getItem(i);
              if (!containsImage(image)) {
                  //addImage(image);
              } else {
                  //removeImage(image);
              }
  
              // refresh the view to
              // mGalleryAdapter.getView(i, view, adapterView);
              mGalleryAdapter.notifyDataSetChanged();
          }
      });
  
  }
  
  @Override
  public void onScrollChange(View view, int i, int i1, int i2, int i3) {
  
      toolbar.setAlpha(getAlphaforActionBar(view.getScrollY()));
  
  }
  private int getAlphaforActionBar(int scrollY) {
      int minDist = 0,maxDist = 650;
      if(scrollY&gt;maxDist){
          return 255;
      }
      else if(scrollY&lt;minDist){
          return 0;
      }
      else {
          int alpha = 0;
          alpha = (int)  ((255.0/maxDist)*scrollY);
          return alpha;
      }
  }
  
  
  class ViewHolder {
      ImageView mThumbnail;
      // This is like storing too much data in memory.
      // find a better way to handle this
      Image mImage;
  }
  
  public class ImageGalleryAdapter extends ArrayAdapter&lt;Image&gt; {
  
      public ImageGalleryAdapter(Context context) {
          super(context, 0);
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          ViewHolder holder;
          if (convertView == null) {
              convertView = LayoutInflater.from(getContext()).inflate(R.layout.enhanced_gallery_adapter, null);
              holder = new ViewHolder();
              holder.mThumbnail = (ImageView) convertView.findViewById(R.id.pp__thumbnail_image);
              convertView.setTag(holder);
          } else {
              holder = (ViewHolder) convertView.getTag();
          }
  
          Image image = getItem(position);
          boolean isSelected = containsImage(image);
  
          convertView.setForeground(isSelected ? getResources().getDrawable(R.drawable.gallery_photo_selected) : null);
  
          if (holder.mImage == null || !holder.mImage.equals(image)) {
              mImageFetcher.loadImage(image.mUri, holder.mThumbnail);
              holder.mImage = image;
          }
          return convertView;
      }
  }
  public boolean containsImage(Image image) {
      return mSelectedImages.contains(image);
  }
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.menu_main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
          case android.R.id.home:
              finish();
              return true;
          case R.id.action_settings:
              return true;
      }
      return super.onOptionsItemSelected(item);
  }
  
  }
  </code></pre>