Android Gradle Problem with Multidex Build on API 19

I have a project in which I turned on multidex to avoid the 65k limit , as well as productFlavors (dev API 21 and prod API 19) to configure. Building my project on API 21 Success ie dev is successful, but on API 19 that is a prod flavor, it constantly gives me an exception in the shrink{component}MultiDexComponents

Complete the error log:

 :app:shrinkProdDebugMultiDexComponents FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:shrinkProdDebugMultiDexComponents'. > java.io.IOException: Can't read [{Project Path}/app/build/intermediates/multi-dex/prod/debug/allclasses.jar] (Can't process class [com/olivephone/office/a/b/e/p.class] (Unknown verification type [17] in stack map frame)) 

build.gradle

 apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion '23.0.0' defaultConfig { applicationId '{Project Name}' minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" multiDexEnabled true } productFlavors { dev { // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin // to pre-dex each module and produce an APK that can be tested on // Android Lollipop without time consuming dex merging processes. minSdkVersion 21 } prod { // The actual minSdkVersion for the application. minSdkVersion 19 } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:appcompat-v7:23.0.1' compile 'com.android.support:recyclerview-v7:23.0.1' compile 'com.android.support:cardview-v7:23.0.1' compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2' compile 'com.google.code.gson:gson:2.3.1' compile 'com.google.android.gms:play-services:8.1.0' compile 'com.android.support:multidex:1.0.1' compile files('libs/linkedin-j-android.jar') compile files('libs/itsrts-pptviewer.jar') compile files('libs/signpost-core-1.2.1.1.jar') compile 'org.twitter4j:twitter4j-core:4.0.2' compile files('libs/universal-image-loader-1.9.2-SNAPSHOT-with-sources.jar') compile files('libs/dropbox-android-sdk-1.6.3.jar') compile files('libs/json_simple-1.1.jar') compile 'com.joanzapata.pdfview:android-pdfview: 1.0.1@jar ' compile 'com.facebook.android:facebook-android-sdk:4.1.0' } 

Any help please anyone

+7
android android-multidex
source share
6 answers

Support for multiple applications for Android 5.0 and higher

Android 5.0 and above uses a runtime called ART, which initially supports downloading multiple dex files from the application’s APK files. FIGURE ART pre-compiles during installation of an application that scans classes (..N) .dex and compiles them into a single .oat file for execution on an Android device. For more information about Android 5.0, see Introducing ART.

That's why your application works great at API level 21.

Multidex support up to Android 5.0

Platform versions prior to Android 5.0 use Dalvik runtime to execute application code. By default, Dalvik restricts applications to one classes.dex for each APK. To get around this limitation, you can use the multidex support library, which becomes part of the main DEX file of your application, and then controls access to additional DEX files and the code that they contain.

So firstly, make sure you import the correct dependency, which seems like you did.

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

In the manifest, add the MultiDexApplication class from the multidex support library to the application element.

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

Alternatively, if your application extends the Application class, you can override the attachBaseContext() method and call MultiDex.install(this) to enable multidex .

 public void onCreate(Bundle arguments) { MultiDex.install(getTargetContext()); super.onCreate(arguments); ... } 

I hope this helps you.

+8
source share

In API 21, the command :app:shrinkProdDebugMultiDexComponents not called because API 21 already uses ART instead of Dalvik. Thus, multidexes are initially supported.

For APIs below 21, the command is executed :app:shrinkProdDebugMultiDexComponents . Checking your build.gradle everything looks great, which leads me to the following.

Is multidex support configured correctly?

Have you installed a manifest to support Multidex?

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

OR, if you really extend the application class, you can do this:

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

or use this "prebuilt" version

 public class MyApplication extends MultiDexApplication{ ... } 
+1
source share

I did not look into this logic, but in my case it was due to version conflicts compile 'com.android.support:appcompat-v7:25.3.1' and compile 'com.google.android.gms:play-services:10.2.4' in my build.gradle file.

Only the inclusion of multidex did not help me. When looking for other solutions, I found that some people complain about the strange play-services version conflict issue. So, I reverted the code changes and finally changed the version of play-services from 10.2.4 to 10.2.1 and it worked for me.

+1
source share

Change your dependencies as shown below:

Edited Dependencies:

 compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.0.1' compile 'com.android.support:recyclerview-v7:23.0.1' compile 'com.android.support:cardview-v7:23.0.1' compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2' compile 'com.google.code.gson:gson:2.3.1' compile 'com.google.android.gms:play-services:8.1.0' compile 'com.android.support:multidex:1.0.1' compile 'com.googlecode.linkedin-j:linkedin-j-core:1.0.416' compile 'oauth.signpost:signpost-core:1.2.1.2' compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4' compile 'com.googlecode.json-simple:json-simple:1.1' compile 'org.twitter4j:twitter4j-core:4.0.2' compile files('libs/itsrts-pptviewer.jar') compile files('libs/dropbox-android-sdk-1.6.3.jar') compile 'com.joanzapata.pdfview:android-pdfview: 1.0.1@jar ' compile 'com.facebook.android:facebook-android-sdk:4.1.0' 

The reason is that 'compile fileTree (dir:' libs ', include: [' * .jar '])' includes the entire jar file in gradle, which is located in the libs folder.

Thanks.!!

0
source share

The shrinkProdDebugMultiDexComponents task calls Proguard , so this error occurs from the Proguard code,

I assume that you are not using the latest version of the Olive Office SDK (which is probably confused with an error or incorrectly configured version of Proguard). If so, get the latest SDK developer.

For a workaround, check out this similar error. Although it has been closed with wontfix status, this blogpost describes how to fix Proguard code.

Also check this one and which is answered by Eric Lafortune (author of Proguard) on similar issues.

0
source share

Crash issue resolved. I removed some unused dependency as well as the remote rx java io.reactivex.rxjava . Instead of Rx java, I added some dummy classes in my package, which is already described here https://realm.io/docs/java/latest .

 // File 1 package io.reactivex; public class Flowable { } // File 2 package io.reactivex; public class Observable { } // File 3 package io.reactivex; public enum BackpressureStrategy { LATEST; } 
0
source share

All Articles