java - 在Android Studio Project中添加外部jar文件

标签 java android jar gradle

我在Android Studio项目中添加了mapsforge版本0.3.0和0.3.1 jar文件。

这是我的build.gradle文件

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

apply plugin: 'android'
repositories {
mavenCentral()
}

android {
compileSdkVersion 19
buildToolsVersion "19.1.0"

sourceSets {
    main {
        manifest.srcFile 'src/main/AndroidManifest.xml'
        java.srcDirs = ['src/main/java']
        resources.srcDirs = ['src/main/resources']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['src/main/res']
        assets.srcDirs = ['assets']
    }

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

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')


        defaultConfig {
            minSdkVersion 9
            targetSdkVersion 19
        }
    }
}

dependencies {
compile ('com.android.support:support-v4:13.0.+')
compile files ('libs/mapsforge-map-0.3.0-SNAPSHOT-jar-with-dependencies.jar','libs/mapsforge-map-0.3.1-SNAPSHOT-jar-with-dependencies.jar')
}

我在gradle.properties中有这个
#Wed Jun 11 16:12:51 PHT 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip

当我同步gradle时:

~~~~~~~~显示此错误~~~~~~~
Error:(4, 0) Build script error, unsupported Gradle DSL method found: 'compile()'!**

Possible causes could be:  
- you are using Gradle version where the method is absent (<a href="open_gradle_settings">Fix Gradle settings</a>)
- you didn't apply Gradle plugin which provides the method (<a href="apply_gradle_plugin">Apply Gradle plugin</a>)
- or there is a mistake in a build script (<a href="goto_source">Goto source</a>)

请帮助我在这里停留2天。

最佳答案

将jar文件放在项目资源管理器中项目的libs文件夹中,如果不存在,则应位于-project name- / app / libs /下。

然后只需将此捕获全部放入您的build.gradle中即可。

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
}

您也可以尝试更新到gradle 1.12更改
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip


distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip

关于java - 在Android Studio Project中添加外部jar文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24938123/

相关文章:

java - 在 Android 3.0 中,当没有 native 代码库时,我无法使用 ndk-build 调试 native 代码错误

android - Sum 查询在 sqlite 中没有得到正确的输出

android - 数据绑定(bind)差异文本或应用

java - 为什么我的多 jar 应用程序似乎没有注意到包含一类唯一字段的 JAR 中的更改?

java - Tomcat:热部署新 jar

maven - 如何将JAR部署到Maven远程仓库

java - 编译jaxb生成的类时编译失败

java - 检查邻接矩阵中的循环?

java - 在 Hibernate 5 中实现 NamingStrategy(使自动生成的列名称大写)

java - 从用户绘制的图像中裁剪掉空白