1

I have an issue with gradle when importing this mongoDB jar driver in android studio. I am getting this error:

Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_25\bin\java.exe'' finished with non-zero exit value 2

When i import the mongo-java-driver-2.13.0-rc0.jar driver i have no issue with this. I do not know if this is relevant but first i imported this driver and then any other mongoDB driver is having this error except from this one that i added first. Here is my gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    useLibrary 'org.apache.http.legacy'

    repositories {
        mavenCentral()
        jcenter()

    }

    defaultConfig {
        applicationId "com.example.irakl_000.maps"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'com.android.support:design:23.1.0'
    compile 'com.android.support:percent:23.1.0'
    compile 'com.facebook.android:facebook-android-sdk:4.7.0'
    compile 'de.hdodenhof:circleimageview:2.0.0'
    compile 'com.isseiaoki:simplecropview:1.0.13'
    compile files('libs/mongo-java-driver-3.2.0-SNAPSHOT.jar')

Any answers to similar questions in stackoverflow did not help, so any help is much appreciated!

EDIT: I created a new project and there are no errors, so obviously something is wrong with the project and not with the grandle file or jar

EDIT: When i run gradle compileDebug --stacktrace i get the following

* Exception is:             
org.gradle.execution.TaskSelectionException: Task 'compileDebug' is ambiguous in root project 'Maps'. Candidates are: 'compileDebugAidl', 'compileDebugAndroidTestAidl', 'compileDebu
gAndroidTestJavaWithJavac', 'compileDebugAndroidTestNdk', 'compileDebugAndroidTestRenderscript', 'compileDebugAndroidTestSources', 'compileDebugJavaWithJavac', 'compileDebugNdk', 'c
ompileDebugRenderscript', 'compileDebugSources', 'compileDebugUnitTestJavaWithJavac', 'compileDebugUnitTestSources'.
        at ...

2 Answers2

0

It looks like you're depending on a single jar twice between these two dependencies:

compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/mongo-java-driver-3.2.0-SNAPSHOT.jar')

The first line is declaring a dependency on everything in the libs directory. The second line is then adding another dependency on a specific jar in the libs folder, which was already covered in the first line. You're effectively telling gradle to use that jar twice, which could cause problems. You're probably also getting a message from gradle to run the build again with different command line flags to see more detailed errors, so do that as well.

Consider removing one or the other. If you have other jars in the libs folder, you'll probably want to remove the second line.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Did you follow gradle's suggestion to run it again with different flags to see more details? – Doug Stevenson Mar 09 '16 at 18:51
  • I do not know how to do what you told me. If you could guide it would be much appreciated :) I am getting this on gradle console > Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. –  Mar 09 '16 at 19:10
  • I edited the question if that's what you wanted me to do, i run 'gradle compileDebug --stacktrace' –  Mar 10 '16 at 15:23
  • Looks like you gave it an invalid target. Use the same one that Android Studio would use: assembleDebug – Doug Stevenson Mar 10 '16 at 17:35
0

You may have a problem with the limit of 65k methods allowd on an android studio project. Google announced a solution to this problem. You can find more information here. I had a similar problem and this was the solution for me so you could give a try.

UPDATE I should mention that this could seriously reduce your gradle build time so you should use it only if there is no other way. The best think you can do is to reduce the libraries you use to the ones you need.

You can also refer to this answer to reduce your google-play-services to the ones you actually need.

Community
  • 1
  • 1
Iraklis Bekiaris
  • 1,163
  • 15
  • 43