Android支持multidex库实现

Android支持multidex库实现

本文介绍了Android支持multidex库实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我达到了神奇的dex限制,因为我的应用程序使用了很多jar(驱动器API,greendao,text to pdf,support ..).

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

我当前的解决方案是我从字面上从主apk调用的谷歌驱动器创建了第二个apk.但是现在我发现android终于在这个库中支持了这一点.我的问题是我不知道如何实现(最好是不使用gradle).我找不到适合的教程.

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我正在迷失方向来尝试执行此操作...我发现

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

我添加了:

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

到我的清单文件和

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

到我的mainactivity.java

To my mainactivity.java

还为Eclipse安装了gradle插件,导出了gradle以获取我更改为的build.gradle文件:

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'
      }
   }
}

但是错误仍然相同:(

推荐答案

博客是旧的解决方案.

使用Android Studio 0.9.2& Gradle插件0.14.1,您只需要:

With Android Studio 0.9.2 & Gradle Plugin 0.14.1, you only need to:

  1. 添加到AndroidManifest.xml:

  1. Add to AndroidManifest.xml:

.

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

添加

MultiDex.install(this);

在自定义应用程序的attachBaseContext方法中

in your custom Application's attachBaseContext method

或您的自定义应用程序扩展MultiDexApplication

or your custom Application extend MultiDexApplication

  1. 在您的build.gradle中添加multiDexEnabled = true

.

android {
    defaultConfig {
        ...
        multiDexEnabled = true
    }
}

完成.

对不起,我的英语不好

相关资源:

http://developer.android.com/tools/building/multidex.html

https://plus.google.com/+XavierDucrohet/posts/1FnzwdcBnyC

这篇关于Android支持multidex库实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 04:57