title: Android project built with gradle crashes with an Out of Memory Error
body: <p>I have an android project originally coded with ADT, it has several dependencies on library projects and jar files such as ActionBarSherlock and ViewPageIndicator, it runs just fine at this point, but I had to move to Android Studio and exported the project from Eclipse to generate the gradle files, after some struggling with it to get it to build which included removing usage of the android_support_v4.jar from several of the library projects that used it and creating a new empty module with a dependency on android_support_v4 in studio and having my libraries depend on that instead I was able to build and run the project from Android Studio onto my device, however, as soon as the app comes up, it does show my main activity but it hangs and after a few seconds I get an Out of Memory error and there is reference in the stack trace to one of my fragments which uses ActionBarSherlock, however I have not changed a single .java file or any other piece of source code, it was all adding .gradle and .iml files and removing the android_support_v4.jar files from my libs.</p>
  
  <p>Here are my build.gradle and settings.gradle files for the main module:</p>
  
  <p><strong>build.gradle:</strong></p>
  
  <pre><code>buildscript {
  repositories {
      mavenCentral()
  }
  dependencies {
      classpath 'com.android.tools.build:gradle:0.5.+'
  }
  }
  apply plugin: 'android'
  
  repositories {
      mavenCentral()
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: '*.jar')
      compile project(':JakeWharton-ActionBarSherlock-e5c2d1c:library')
      compile project(':JakeWharton-ViewPagerIndicator-2.4.1-8cd549f:library')
      compile project(':DevsmartLibrary')
      compile project(':android-numberpicker:library')
      compile project(':Android-Universal-Image-Loader:library')
      compile project(':android-xmlrpc')
      compile project(':StickyListHeadersLibrary')
      compile project(':AndroidSupport')
  }
  
  android {
      compileSdkVersion 18
      buildToolsVersion "17.0.0"
  
      defaultConfig {
          minSdkVersion 10
          targetSdkVersion 16
      }
  
      sourceSets {
          main {
              manifest.srcFile 'AndroidManifest.xml'
              java.srcDirs = ['src']
              resources.srcDirs = ['src']
              res.srcDirs = ['res']
              assets.srcDirs = ['assets']
          }
  
      }
  }
  </code></pre>
  
  <p><strong>settings.gradle:</strong></p>
  
  <pre><code>include ':'
  include ':AndroidSupport'
  include ':android-numberpicker:library'
  include ':JakeWharton-ViewPagerIndicator-2.4.1-8cd549f:library'
  include ':android-xmlrpc'
  include ':JakeWharton-ActionBarSherlock-e5c2d1c:library'
  include ':StickyListHeadersLibrary'
  include ':Android-Universal-Image-Loader:library'
  include ':DevsmartLibrary'
  </code></pre>
  
  <p>And the <strong>build.gradle</strong> file for my dummy module AndroidSupport:</p>
  
  <pre><code>buildscript {
      repositories {
          mavenCentral()
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:0.5.+'
      }
  }
  apply plugin: 'android-library'
  
  repositories {
      mavenCentral()
  }
  
  android {
      compileSdkVersion 17
      buildToolsVersion "17.0.0"
  
      defaultConfig {
          minSdkVersion 7
          targetSdkVersion 15
      }
  
      sourceSets {
          main {
              manifest.srcFile 'src/main/AndroidManifest.xml'
          }
  
      }
  }
  
  dependencies {
      compile 'com.android.support:support-v4:13.0.0'
  }
  </code></pre>
  
  <p>I don't even know were to start looking because, as I mentioned, I did not change any sourcecode, any pointers will be greatly appreciated.</p>
  
  <p><strong>EDIT 1:</strong>
  In case it helps with anything, here is my stacktrace from logcat:</p>
  
  <pre><code>10-16 10:02:46.968: I/dalvikvm-heap(6323): Clamp target GC heap from 49.642MB to 48.000MB
  10-16 10:02:46.968: D/dalvikvm(6323): GC_FOR_ALLOC freed 0K, 1% free 48713K/49159K, paused 322ms
  10-16 10:02:46.968: I/dalvikvm-heap(6323): Forcing collection of SoftReferences for 272-byte allocation
  10-16 10:02:47.328: I/dalvikvm-heap(6323): Clamp target GC heap from 49.642MB to 48.000MB
  10-16 10:02:47.332: D/dalvikvm(6323): GC_BEFORE_OOM freed 0K, 1% free 48713K/49159K, paused 360ms
  10-16 10:02:47.332: E/dalvikvm-heap(6323): Out of memory on a 272-byte allocation.
  10-16 10:02:47.332: I/dalvikvm(6323): "main" prio=5 tid=1 RUNNABLE
  10-16 10:02:47.332: I/dalvikvm(6323):   | group="main" sCount=0 dsCount=0 obj=0x40a74460 self=0x11a2828
  10-16 10:02:47.332: I/dalvikvm(6323):   | sysTid=6323 nice=0 sched=0/0 cgrp=default handle=1074467976
  10-16 10:02:47.332: I/dalvikvm(6323):   | schedstat=( 0 0 0 ) utm=698 stm=41 core=0
  10-16 10:02:47.332: I/dalvikvm(6323):   at java.lang.Throwable.nativeFillInStackTrace(Native Method)
  10-16 10:02:47.332: I/dalvikvm(6323):   at java.lang.Throwable.fillInStackTrace(Throwable.java:160)
  10-16 10:02:47.332: I/dalvikvm(6323):   at java.lang.Throwable.&lt;init&gt;(Throwable.java:83)
  10-16 10:02:47.332: I/dalvikvm(6323):   at java.lang.Error.&lt;init&gt;(Error.java:37)
  10-16 10:02:47.332: I/dalvikvm(6323):   at java.lang.VirtualMachineError.&lt;init&gt;(VirtualMachineError.java:35)
  10-16 10:02:47.332: I/dalvikvm(6323):   at java.lang.OutOfMemoryError.&lt;init&gt;(OutOfMemoryError.java:33)
  10-16 10:02:47.332: I/dalvikvm(6323):   at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:-1)
  10-16 10:02:47.332: I/dalvikvm(6323):   at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:145)
  10-16 10:02:47.332: I/dalvikvm(6323):   at java.lang.StringBuilder.append(StringBuilder.java:216)
  10-16 10:02:47.332: I/dalvikvm(6323):   at com.my.project.containers.Banner.getImageUrl(Banner.java:57)
  10-16 10:02:47.332: I/dalvikvm(6323):   at com.my.project.fragments.BannerFragment.newInstance(BannerFragment.java:51)
  10-16 10:02:47.332: I/dalvikvm(6323):   at com.my.project.adapters.BannerItemFragmentPagerAdapter.getFragment(BannerItemFragmentPagerAdapter.java:143)
  10-16 10:02:47.332: I/dalvikvm(6323):   at com.my.project.adapters.BannerItemFragmentPagerAdapter.getItem(BannerItemFragmentPagerAdapter.java:92)
  10-16 10:02:47.332: I/dalvikvm(6323):   at android.support.v4.app.FragmentPagerAdapter.instantiateItem(FragmentPagerAdapter.java:97)
  10-16 10:02:47.332: I/dalvikvm(6323):   at com.my.project.adapters.BannerItemFragmentPagerAdapter.instantiateItem(BannerItemFragmentPagerAdapter.java:111)
  10-16 10:02:47.336: I/dalvikvm(6323):   at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:829)
  10-16 10:02:47.336: I/dalvikvm(6323):   at android.support.v4.view.ViewPager.populate(ViewPager.java:1044)
  10-16 10:02:47.336: I/dalvikvm(6323):   at android.support.v4.view.ViewPager.populate(ViewPager.java:911)
  10-16 10:02:47.336: I/dalvikvm(6323):   at android.support.v4.view.ViewPager.setOffscreenPageLimit(ViewPager.java:692)
  10-16 10:02:47.336: I/dalvikvm(6323):   at com.my.project.fragments.HomeFragment$BannersListener$1.run(HomeFragment.java:604)
  10-16 10:02:47.336: I/dalvikvm(6323):   at android.app.Activity.runOnUiThread(Activity.java:4170)
  10-16 10:02:47.336: I/dalvikvm(6323):   at com.my.project.fragments.HomeFragment$BannersListener.onBannerListLoaded(HomeFragment.java:582)
  10-16 10:02:47.336: I/dalvikvm(6323):   at com.my.projectd.models.BrowseModel.requestBanners(BrowseModel.java:605)
  10-16 10:02:47.336: I/dalvikvm(6323):   at com.my.project.fragments.HomeFragment$2.run(HomeFragment.java:390)
  10-16 10:02:47.336: I/dalvikvm(6323):   at android.app.Activity.runOnUiThread(Activity.java:4170)
  10-16 10:02:47.336: I/dalvikvm(6323):   at com.my.project.fragments.HomeFragment.updateUIForNetworkState(HomeFragment.java:378)
  10-16 10:02:47.336: I/dalvikvm(6323):   at com.my.project.fragments.HomeFragment.onNetworkStateChanged(HomeFragment.java:314)
  10-16 10:02:47.336: I/dalvikvm(6323):   at com.my.project.fragments.MyBaseFragment$NetworkStatusBroadcastReceiver.onReceive(MyBaseFragment.java:93)
  10-16 10:02:47.336: I/dalvikvm(6323):   at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
  10-16 10:02:47.336: I/dalvikvm(6323):   at android.os.Handler.handleCallback(Handler.java:605)
  10-16 10:02:47.336: I/dalvikvm(6323):   at android.os.Handler.dispatchMessage(Handler.java:92)
  10-16 10:02:47.336: I/dalvikvm(6323):   at android.os.Looper.loop(Looper.java:137)
  10-16 10:02:47.340: I/dalvikvm(6323):   at android.app.ActivityThread.main(ActivityThread.java:4424)
  10-16 10:02:47.340: I/dalvikvm(6323):   at java.lang.reflect.Method.invokeNative(Native Method)
  10-16 10:02:47.340: I/dalvikvm(6323):   at java.lang.reflect.Method.invoke(Method.java:511)
  10-16 10:02:47.340: I/dalvikvm(6323):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  10-16 10:02:47.340: I/dalvikvm(6323):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  10-16 10:02:47.340: I/dalvikvm(6323):   at dalvik.system.NativeStart.main(Native Method)
  10-16 10:02:47.340: W/dalvikvm(6323): Exception thrown (Ljava/lang/OutOfMemoryError;) while throwing internal exception (Ljava/lang/OutOfMemoryError;)
  10-16 10:02:47.652: I/dalvikvm-heap(6323): Clamp target GC heap from 49.641MB to 48.000MB
  10-16 10:02:47.652: D/dalvikvm(6323): GC_FOR_ALLOC freed 1K, 1% free 48712K/49159K, paused 311ms
  10-16 10:02:47.652: D/AndroidRuntime(6323): Shutting down VM
  10-16 10:02:47.656: W/dalvikvm(6323): threadid=1: thread exiting with uncaught exception (group=0x40a731f8)
  </code></pre>
  
  <p><strong>EDIT 2:</strong>
  I had not tried what Ray suggested, I just added android:largeHeap="true" to my manifest and it no longer crashes with the out of memory error but still hangs and then ANR's</p>