簡體   English   中英

在Android Studio項目中添加外部jar文件

[英]Adding external jar files in Android Studio Project

我在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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM