Jigar Makwana
Jigar Makwana

Reputation: 227

build gradle failed when adding jar in android studio

I am using Android Studio for twitter posting demo and have some jar files to be added to build.gradle, I have placed those jars to the libs folder of my project and have added it to build.gradle, When I am trying to sync the gradle, it gives me below error :

Error

  Error:Execution failed for task ':Demotweet:dexDebug'.
    > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_71.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

build.gradle

buildscript {
    repositories {
        mavenCentral()
        jcenter()
        mavenLocal()
        maven {
            name 'maven.aviary.com'
            url uri("http://maven.aviary.com/repo/release")
        }
        maven { url 'https://maven.fabric.io/public' }

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

apply plugin: 'android'
apply plugin: 'io.fabric'


repositories {

    mavenCentral()
    jcenter()
    mavenLocal()
    maven {
        name 'maven.aviary.com'
        url uri("http://maven.aviary.com/repo/release")
    }
    maven { url 'https://maven.fabric.io/public' }
}


dependencies {
    // compile fileTree(dir: 'libs', include: '*.jar')
    //compile 'com.android.support:support-v4:23.0.0'
    compile 'com.soundcloud.android:android-crop:1.0.0@aar'
    compile 'com.aviary.android.feather.sdk:aviary-sdk:3.6.5'
    compile 'com.facebook.android:facebook-android-sdk:4.1.0'
    compile files('picasso-2.5.2.jar')
    compile files('ion-2.1.6.jar')
    compile files('libs/urlimageviewhelper-1.0.4.jar')
    // compile files('libs/android-support-v7-appcompat.jar')
    compile files('androidasync-2.1.6.jar')
    compile files('libs/http_client/commons-codec-1.6.jar')
    compile files('libs/http_client/commons-logging-1.1.3.jar')
    compile files('libs/http_client/fluent-hc-4.3.2.jar')
    compile files('libs/http_client/httpclient-4.3.2.jar')
    compile files('libs/http_client/httpclient-cache-4.3.2.jar')
    compile files('libs/http_client/httpcore-4.3.1.jar')
    compile files('libs/http_client/httpmime-4.3.2.jar')

    /
    compile files('libs/signpost-commonshttp4-1.2.1.1.jar')
    compile files('libs/signpost-core-1.2.1.1.jar')
    compile files('libs/twitter4j-core-4.0.4.jar')
    compile files('libs/twitter4j-media-support-4.0.4.jar')

    //end

    //  compile 'com.google.android.gms:play-services:8.4.0'
    compile project(':google-play-services_libs')
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.google.code.gson:gson:2.2.4'


    compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
        transitive = true;
    }
    compile project(':viewpager_indicatr')

}



android {
    compileSdkVersion 21
    buildToolsVersion '23.0.2'
    dexOptions {

    }

    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }


    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
    defaultConfig {
        multiDexEnabled true
    }

}

I am getting this eror when i am adding below jars for twitter to gradle,

compile files('libs/signpost-commonshttp4-1.2.1.1.jar')
compile files('libs/signpost-core-1.2.1.1.jar')
compile files('libs/twitter4j-core-4.0.4.jar')
compile files('libs/twitter4j-media-support-4.0.4.jar')

Upvotes: 0

Views: 1940

Answers (3)

Osama Abukmail
Osama Abukmail

Reputation: 41

you have to import them from android studio itself right click on your app then choose "open module settings" , then press on the plus green button , choose "import jar package" , then browse and choose your .jar library , then inside the " module settings " again , choose app from the list , then go to dependencies , and click on the green plus button on the right and choose "Module Dependency" then choose your library

Upvotes: 0

naran z
naran z

Reputation: 486

Use compile fileTree(dir: 'libs', include: ['*.jar']) in the dependencies, instead of adding individual .jar file into the build.gradle. It will includes all you jar file placed in the libs folder

Upvotes: 1

Mark Shen
Mark Shen

Reputation: 346

Clean and rebuild project, and reflesh gradle

Upvotes: 0

Related Questions