Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android support multidex library implementation

I have hit the magic dex limit because my application uses a lot of jars (drive API, greendao, text to pdf, support.. ).

My current solution was that I literally created a second apk just for google drive which I called from the main apk. But now I found out that android finally supports this with this library. My problem is just that I don't know how to implement it(preferably without gradle). I can't find any good tutorials for it.

Okey I am losing my mind trying to implement this... I have found this

And I added:

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

To my manifest file and

protected void attachBaseContext(Context base) {
     super.attachBaseContext(base);
     MultiDex.install(this);
}

To my mainactivity.java

Also installed gradle plugin for eclipse, exported gradle to get build.gradle file which I changed to:

apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':android-support-v7-appcompat')
    compile project(':Sync')
    compile project(':gdrive:google-play-services_lib')
}


android {
    compileSdkVersion 14
    buildToolsVersion "21.1.1"


    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src-gen','src']
            resources.srcDirs = ['src-gen','src']
            aidl.srcDirs = ['src-gen','src']
            renderscript.srcDirs = ['src-gen','src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

    dexOptions {
      preDexLibraries = false
   }
}

afterEvaluate {
   tasks.matching {
      it.name.startsWith('dex')
   }.each { dx ->
      if (dx.additionalParameters == null) {
         dx.additionalParameters = ['--multi-dex']
      } else {
         dx.additionalParameters += '--multi-dex'
      }
   }
}

But The error is still the same :(

like image 373
Tadej Vengust Avatar asked Nov 14 '14 07:11

Tadej Vengust


People also ask

What is multidex enabled in Android?

Android applications by default have SingleDex support which limits your application to have only 65536 methods(references). So multidexEnabled = true simply means that now you can write more than 65536 methods(references) in your application.

Why do we need to enable multidex support for apps?

The multidex library will help you avoid build errors, especially when creating complex applications that require numerous dependencies and methods. The error that you will encounter looks like the one below: trouble writing output: Too many field references: 120000; max is 65536. You may try using --multi-dex option.

What is multidex used for?

They are indicated for all types of wounds, including dermal ulcers (e.g., leg ulcers, pressure ulcers and other secreting lesions), diabetic ulcers, abdominal wounds, infected wounds, superficial wounds, lacerations, cuts, abrasions, donor sites and second degree burns. Multidex Powder is indicated for moist wounds.


1 Answers

update:

if you're using androidX you can use this:

implementation 'androidx.multidex:multidex:2.0.1'

reference to all google maven, where you can search for google's artifacts:
https://maven.google.com/web/index.html

like image 52
Mohammad Desouky Avatar answered Oct 21 '22 04:10

Mohammad Desouky