0

My problem is that I have a global class, that have information about my app and I show in other activities,

my AndroidManifest.xml was like this...

<application
    android:name=".Global"      <-------- global class
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/nobar">
 .
 .
</application>

but i have errors java.lang.OutOfMemoryError: GC overhead limit exceeded and 65k limit in dex and i need to change it to...

<application
    android:name="android.support.multidex.MultiDexApplication" <--- changed
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/nobar">
 .
 .
</application>

this is my build.gradle

apply plugin: 'com.android.application'

android {

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

    compileSdkVersion 24
    buildToolsVersion "24.0.0"
    defaultConfig {
        applicationId "com.xx.xx"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 25
        versionName "1.0"
        // Enabling multidex support.
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            signingConfig signingConfigs.xx
            debuggable false
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'

}

but I need the global class to share information about activities...

or there is another way to do this thing??

DarckBlezzer
  • 4,578
  • 1
  • 41
  • 51

4 Answers4

0

In build.gradle, try to change something like below, use multiDexEnabled true

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

    defaultConfig {
        ...
        minSdkVersion 14
        targetSdkVersion 21
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

https://developer.android.com/studio/build/multidex.html

How to enable multidexing with the new Android Multidex support library

Community
  • 1
  • 1
xxx
  • 3,315
  • 5
  • 21
  • 40
  • yes i have that in my `build.gradle` it cause change my manifes, and in there i have a global class name, and i changed it for `android:name="android.support.multidex.MultiDexApplication"` and i need a global class – DarckBlezzer Aug 01 '16 at 20:41
0

Well I has a global class for my project, i did this example of global class

Example of global class with android manifest

My solution for my global class is this example..

Android global variable

Community
  • 1
  • 1
DarckBlezzer
  • 4,578
  • 1
  • 41
  • 51
0

Update your Global Class like this to support MultiDex.

public class Global extends Application {
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
    //rest of your code here
}
0

I've just faced the same issue.

To solve this problem, I fixed Global class like below.

public class Global extends Application  --> before

public class Global extends android.support.multidex.MultiDexApplication --> after

Then, AndroidManifest.xml should be ponting Global class in the name attribute just like you worte before.

<application
    android:name=".Global"
Sugihey
  • 1
  • 2