0

I have successfully created an android application using android studio, and works fine when i run into android emulator or device connected to the development machine, but when i try to install the apk from build/outputs/apk the application crashes on opening.Also i tried to generate signed apk from android studio from build -> Generate signed apk (both release and debug) but it fails to generate the apk with the following error:

Error:Execution failed for task ':app:transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lorg/intellij/lang/annotations/Identifier;

My build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.aitrich.android.modern.photo"
        minSdkVersion 14
        targetSdkVersion 25
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'org.greenrobot.greendao'

ext {
    supportLibraryVersion = '25.0.1'
    playServicesVersion = '9.0.2'
    retrofitVersion = '2.1.0'
}

greendao {
    schemaVersion 1
}

apt {
    arguments {
        stagGeneratedPackageName "com.aitrich.android.modern.stag.generated"
        stagDebug true
    }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'

    compile "com.android.support:design:$supportLibraryVersion"
    compile "com.android.support:support-v13:$supportLibraryVersion"
    compile "com.android.support:cardview-v7:$supportLibraryVersion"
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'org.greenrobot:greendao:3.2.0'
    compile 'com.jakewharton:butterknife:8.4.0'
    compile 'com.intuit.sdp:sdp-android:1.0.3'
    compile 'me.zhanghai.android.materialprogressbar:library:1.3.0'
    compile 'com.mobsandgeeks:android-saripaar:2.0.3'
    compile "com.squareup.retrofit2:retrofit:$retrofitVersion"
    compile "com.squareup.retrofit2:converter-gson:$retrofitVersion"
    compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.vimeo.stag:stag-library:2.0.2'
    compile 'com.github.hotchemi:permissionsdispatcher:2.2.0'
    compile 'com.tapadoo.android:alerter:1.0.6'
    compile 'ch.halcyon:squareprogressbar:1.6.0'
    compile 'com.yalantis:ucrop:2.2.0'
    compile 'com.yalantis:ucrop:2.2.0-native'
    compile 'com.evernote:android-job:1.1.8'
    compile('com.github.silvestrpredko:dot-progress-bar:1.1') {
        exclude group: 'com.android.support', module: 'appcompat-v7'
    }
    compile('com.github.StevenDXC:DxLoadingButton:1.5') {
        exclude group: 'com.android.support', module: 'appcompat-v7'
    }
    compile('com.redmadrobot:chronos:1.0.7') {
        exclude module: 'eventbus:2.4.0'
    }
    compile ('co.infinum:materialdatetimepicker-support:3.1.3') {
        exclude group: 'com.android.support', module: 'design'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'support-v13'
    }
    compile 'com.android.support:multidex:1.0.1'


    apt 'com.jakewharton:butterknife-compiler:8.4.0'
    apt 'com.vimeo.stag:stag-library-compiler:2.0.2'
    apt 'com.github.hotchemi:permissionsdispatcher-processor:2.2.0'
}
David Koelle
  • 20,726
  • 23
  • 93
  • 130
darwin
  • 1,524
  • 1
  • 22
  • 32

2 Answers2

2

Edit:

Please check you having this two libraries common :

 compile 'com.yalantis:ucrop:2.2.0'
 compile 'com.yalantis:ucrop:2.2.0-native'

remove one of them and check which one is needed for you.

Check this answer for multidex issue.that one helped me to fix that issue.

It seems your logcat clearly shows annotations identifier DexException: Multiple dex files define Lorg/intellij/lang/annotations/Identifier. You should remove this line support -annotations:

 androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

Moreover, If you are using google play services bundle like this : compile 'com.google.android.gms:play-services:8.1.0

change into below gms separately for all libraries

compile 'com.google.android.gms:play-services-location:8.1.0'
 compile 'com.google.android.gms:play-services-base:8.1.0'
 compile 'com.google.android.gms:play-services-analytics:8.1.0'
 compile 'com.google.android.gms:play-services-maps:8.1.0'

 compile "com.google.android.gms:play-services-gcm:8.1.0'    //

for gcm push notification

Community
  • 1
  • 1
Stephen
  • 9,899
  • 16
  • 90
  • 137
  • Thank u for ur quick response, but unfortunately i am not using any if the above mentioned dependencies in my project. – darwin Apr 07 '17 at 09:32
  • @darwin where is dex options and packaging options in that edited post gradle file – Stephen Apr 07 '17 at 09:43
  • sorry i forgot it, but still smae issue after adding dexOptions { //incremental = true; preDexLibraries = false javaMaxHeapSize "4g" } packagingOptions { exclude 'META-INF/NOTICE.txt' // will not include NOTICE file exclude 'META-INF/LICENSE.txt' // will not include LICENSE file } – darwin Apr 07 '17 at 09:58
  • @darwin inside the application element in manifest you added this line? android:name="android.support.multidex.MultiDexApplication" – Stephen Apr 07 '17 at 10:06
  • still same issue – darwin Apr 07 '17 at 10:14
  • @darwin can you check [this](http://stackoverflow.com/a/26713987/3960700) – Stephen Apr 07 '17 at 10:25
  • sure, i will check and inform u asap – darwin Apr 07 '17 at 10:37
  • i dont know how to remove android-support-v4.jar – darwin Apr 07 '17 at 10:42
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/140167/discussion-between-stephen-and-darwin). – Stephen Apr 07 '17 at 10:50
0

Try enabling multidex . inside app level build.gradle write these lines

   android {
...
   defaultConfig {
       ...
       // Enabling multidex support.
       multiDexEnabled true
       ...
   }

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

check this for more info

Manohar
  • 22,116
  • 9
  • 108
  • 144