在android studio中添加jar时,build gradle失败了

时间:2016-06-02 10:18:02

标签: android android-studio android-gradle build.gradle

我正在使用Android Studio进行Twitter发布演示并将一些jar文件添加到build.gradle,我已将这些jar放到我项目的libs文件夹中并将其添加到{{ 1}},当我尝试同步build.gradle时,它会给出以下错误:

错误

gradle

的build.gradle

  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

当我在下面添加jars for twitter to 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
    }

}

3 个答案:

答案 0 :(得分:1)

在依赖项中使用NSArray,而不是将单个compile fileTree(dir: 'libs', include: ['*.jar'])文件添加到build.gradle中。它将包含放置在.jar文件夹

中的所有jar文件

答案 1 :(得分:0)

清理并重建项目,并重新制作草图

答案 2 :(得分:0)

你必须从android studio本身导入它们 右键单击您的应用,然后选择“打开模块设置” ,然后按加号绿色按钮,选择“导入jar包” ,然后浏览并选择.jar库 ,然后再次在“模块设置”中,从列表中选择应用程序,然后转到依赖项,然后单击右侧的绿色加号按钮并选择“模块依赖项”,然后选择您的库