Android Media Library Support

I hit the dex magic limit because my application uses a lot of cans (api disk, greendao, text in pdf, support ..).

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

Okey I'm going crazy trying to realize this. I found this: http://blog.osom.info/2014/10/multi-dex-to-rescue-from-infamous-65536.html

And I added:

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

To manifest file and

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

In my mainactivity.java

Also installed is the gradle plugin for eclipse, exported gradle to get the 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 remains the same: (

+11
android android-gradle android-library dex
Nov 14 '14 at 7:47
source share
3 answers

Blogging was an old solution.

With Android Studio 0.9.2 and Gradle Plugin 0.14.1 you only need:

  • Add to AndroidManifest.xml:

.

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

or

Add

 MultiDex.install(this); 

in your user application attachBaseContext method

or your custom MultiDexApplication application MultiDexApplication

  1. add multiDexEnabled = true to your build.gradle

.

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

Done.

Sorry for bad english

Related Resources:

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

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

+17
Nov 14 '14 at 8:43
source share

There are a few things you need to do

1- In your gradle, you need to specify multidex and add a support library:

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

2- In the manifest, you must install the application in an application with several applications:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.package.name"> <application ... android:name="com.package.name.my_application"> ... </application> </manifest> 

3.1- In your application class, you must either extend MultiDexApplication :

 public class my_application extends MultiDexApplication { ... } 

3.2- Or above the attachBaseContext() method:

 public class my_application extends Application { protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } } 

Multidex Support Library Limitations

The Multidex Support Library has some well-known limitations that you should be aware of and verify when you include them in the application build configuration:

  • Installing .dex files during startup on a device data section is complex and can lead to Application Not Response (ANR) errors if the secondary dex files are large. In this case, you should use code reduction techniques with ProGuard to minimize dex file size and remove unused portions of code.
  • Applications that use multidex may not run on devices that run platform versions earlier than Android 4.0 (API level 14) due to a Dalvik linearAlloc error (issue 22586). If you focus on API levels earlier than 14, be sure to test with these versions of the platform, since your application may have problems at startup or when certain class groups load. Code reduction can reduce or possibly eliminate these potential problems.
  • Applications that use the multidex configuration, which execute very large memory allocation requests, may crash at runtime due to the DalvikAlloc limit (release 78035). The distribution limit has been increased in Android 4.0 (API level 14), but applications can still work in this limit for Android versions up to Android 5.0 (API level 21).
  • There are complex requirements regarding which classes are needed in the main dex file when executed in the Dalvik runtime. Updates to the Android build tool support Android requirements, but it is possible that other included libraries have additional dependency requirements, including using introspection or calling Java methods from native code. Some libraries may not be available until the multidex build tools are updated so that you can specify the classes that should be included in the main dex file.

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

+15
Jan 19 '15 at 8:13
source share

According to the docs at https://developer.android.com/studio/build/multidex.html#avoid

If you minSdkVersion are 21 and above, all you have to do is

 android { defaultConfig { ... minSdkVersion 21 targetSdkVersion 25 multiDexEnabled true } ... } 

if you minSdkVersion is 20 or lower, you need to use the support library

 android { defaultConfig { ... minSdkVersion 15 targetSdkVersion 25 multiDexEnabled true } ... } dependencies { compile 'com.android.support:multidex:1.0.1' } 

Along with

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp"> <application android:name="android.support.multidex.MultiDexApplication" > ... </application> </manifest> 
+1
May 24 '17 at 6:13
source share



All Articles