6

I am developing an application which enabling Multidex in order to avoid 65k limit. I want to add an external library in Jar type (i.e. iPay Jar SDK). I've Synchronized the Gradle and succeed but I failed to run the project.

The error message shown like below

Error:Execution failed for task ':app:shrinkDebugMultiDexComponents'.

java.io.IOException: Can't read [/[dir]/app/build/intermediates/multi-dex/debug/allclasses.jar] (Can't process class [com/ipay/IpayAcitivity.class] (Unknown verification type [14] in stack map frame))

This is my Gradle Code

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '3.2'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

repositories {
    mavenCentral()
    mavenLocal()
}

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        resourcePackageName '[My Package]'
    }
}

dependencies {
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"

    compile fileTree(dir: 'libs', include: ['*.jar'])
    //Libs folder contains: org.apache.http.legacy.jar
    //and ipay88_androidv7.jar

    compile 'com.loopj.android:android-async-http:1.4.5'
    compile 'com.github.rey5137:material:1.2.1'
    compile 'com.jpardogo.materialtabstrip:library:1.0.9'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'

    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'com.facebook.android:facebook-android-sdk:4.7.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "[My Application Id]"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets {
        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java', 'build/source/apt/debug']
            resources.srcDirs = ['src/main/res']
            res.srcDirs = ['src/main/res']
            assets.srcDirs = ['src/main/assets']
        }

        beta {
            resources.srcDirs = ['app/src/beta/res']
            res.srcDirs = ['app/src/beta/res']
        }
    }
    signingConfigs {
        release {
            ...
        }
    }
}

Before I added this type of external library (i.e. iPay Jar SDK), the application was running successfully. But the problem arised after I had added iPay Jar SDK (second Jar Library).

For further information, I had already followed this guide on https://developer.android.com/tools/building/multidex.html But it didn't work my project.

What's your suggestion to fix this error ?

Izzuddiin
  • 265
  • 2
  • 12
  • Clearly there's a problem with iPay SDK, and more specifically with `com/ipay/IpayAcitivity.class`. Since the SDK is not publicly available, I can't really check that by myself. Have you tried to contact iPay's support? – Alex Lipov Dec 29 '15 at 09:14
  • @AlexLipov Yes, I have contact the support team of IPay. But, they haven't gave the answer. When I tried to implement the SDK on another new project (without multidex, without 3rd party lib), the project could run without error. – Izzuddiin Dec 30 '15 at 01:34
  • This exception comes from Proguard (app:shrinkDebugMultiDexComponents task internally invokes Proguard - see my answer [here](http://stackoverflow.com/a/27207969/1233652)). Therefore, if you'll set `minifyEnabled` to true in the second project, then most probably you'll have the same error. – Alex Lipov Dec 30 '15 at 08:30
  • @Izzuddiin did you find a solution for it . I am also having the same issue.But using a different sdk (Unity). – Sunil Sunny Mar 01 '16 at 13:19
  • @sunilsunny My assumption, the cause of this problem because this SDK didn't compatible with Multidex Library. So, I decompiled the SDK Jar, get the java class version of the SDK, fix it, and use it. – Izzuddiin Mar 16 '16 at 04:17
  • @Izzuddiin Yes it was because unity library was not compatible with Multidex.I found 2 solutions 1)Updated the Unity library to the latest which solved the problem.2)Use only required play service ie in my case I only required the gms for ads and this will allow as to remove multidex from application. – Sunil Sunny Mar 16 '16 at 04:48

2 Answers2

0

Try this:

public class MyApplication extends MultiDexApplication
{
    @Override
    protected void attachBaseContext(Context base)
    {
        super.attachBaseContext( base );
    }

    @Override
    public void onCreate()
    {
        MultiDex.install(getTargetContext());
        super.onCreate();
    }

}
oalpayli
  • 227
  • 1
  • 2
  • 9
  • I've implemented that class. But still not working. :'( – Izzuddiin Dec 29 '15 at 01:17
  • try this then; android{ buildTypes { release { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' minifyEnabled true // Add this line shrinkResources true // Add this line } } } – oalpayli Dec 29 '15 at 10:15
  • Thank you for your answer, but it's still not working, Sir. Result same error message – Izzuddiin Dec 30 '15 at 01:33
0

It seems your library is not compatible with Multidex. So you better update the library to the latest version(if an update is available). Or use only the required Google Play services API in your application and get rid off Multidex. Replace

  compile 'com.google.android.gms:play-services:8.1.0'  (the whole library)

this with something you use in your app like this

 compile 'com.google.android.gms:play-services-ads:8.1.0'  (library only for ads)

and remove this compile 'com.android.support:multidex:1.0.1'

You can find all the Google Play services API here https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project

Sunil Sunny
  • 3,949
  • 4
  • 23
  • 53