【问题标题】:Gradle Build fail when i import an external library当我导入外部库时,Gradle Build 失败
【发布时间】:2016-06-21 18:57:35
【问题描述】:

我在我的 android studio 项目中添加了一个新库,现在运行它时出现此错误:

UNEXPECTED TOP-LEVEL ERROR: 
Execution failed for task ':app:preDexDebug'.
>com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command' /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java" finished with non-zero value 3
BUILD FAILED
Total time:17 mins 33.841 secs
1 error
0 warning

我在 app/libs 中添加了库。我使用右键单击并添加为库。 add as library

我读到如果我将库放在外部库而不是 Project/app/libs 中,可能会修复此错误,但我不知道该怎么做。 External libraries

这是我的构建 gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.nameht.pruebas"
        minSdkVersion 15
        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.2.0'
    compile files('libs/symja-2016-03-07.jar')
}

【问题讨论】:

    标签: android android-studio jar build.gradle


    【解决方案1】:

    您正在导入 lib 两次。使用此compile fileTree(include: ['*.jar'], dir: 'libs') 的和使用此compile files('libs/symja-2016-03-07.jar') 的。尝试删除其中一个,事情应该可以正常工作。我建议删除此compile files('libs/symja-2016-03-07.jar'),因为这样您就不必担心单独从 lib 添加 jar。

    你的 gradle 文件应该是这样的 -

    apply plugin: 'com.android.application'
    
    repositories { 
        mavenCentral()
        flatDir {                      <-- This is important
            dirs 'libs'
        }
    }
    
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.2"
    
        defaultConfig {
            applicationId "com.example.nameht.pruebas"
            minSdkVersion 15
            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.2.0'
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-18
      • 1970-01-01
      • 2019-01-28
      • 1970-01-01
      • 2016-10-18
      • 1970-01-01
      • 2014-06-24
      相关资源
      最近更新 更多