0

我收到错误:

Gradle: error: package de.congrace.exp4j does not exist

我将 exp4j.jar 文件添加到项目中: TestProject-idea-libraries ,这是正确的还是我必须在哪里正常添加它?

我也尝试在 build.gradle 文件中添加

dependencies {
compile ('libs/exp4j.jar')
}

但它没有用,Test-src-build.gradle 中还有第二个 gradle 文件,如下所示:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 18
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
}

我不知道该怎么办...有人可以帮忙吗?编辑:我还在资源管理器中手动添加了文件 exp4j.jar ... Test/build/libs 文件夹,但它仍然无法正常工作...

4

1 回答 1

0

See the Gradle doc:

1) You could write

dependencies {
    compile files('libs/exp4j-0.3.10.jar')
}

or 2) define the libs directory as repository

repositories {
    flatDir dirs:'libs'
}

and then reference it with

dependencies {
    compile 'de.congrace:exp4j:0.3.10'
}

or 3) you do not place it in the libs directory and declare it as a standard dependency from Maven central:

dependencies {
    compile 'de.congrace:exp4j:0.3.10'
}

Do not mix IDEA settings with Gradle settings. If you add the library to IDEA compile path, Gradle will not know about this setting. If you add the library to Gradle and execute a Gradle build in IDEA then it will work.

Update: all 3 variants are tested and are working!

于 2013-10-27T18:16:46.233 回答