用Intellij IDEA开发Android依赖第三方库和工程

1.使用maven库
首先在app/build.gradle库中添加mavenCentral

repositories {
    mavenCentral()
}

然后在dependencies里面添加依赖,语法是compile 'groupId:artifactId:version'

dependencies {
    compile 'com.mcxiaoke.volley:library:1.0.8'
}


2.使用本地jar包

首先把jar包添加到工程的libs目录下,比如我们添加litepal-1.1.1.jar

用Intellij IDEA开发Android依赖第三方库和工程

然后在把libs里所有的jar添加到依赖中,添加完之后别忘了重新构建一下。

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


3.依赖第三方工程

首先在项目的根目录下建一个libs文件夹,不建也可以,这是为方便管理。

把需要依赖的工程拷贝到libs文件夹下面,这里我们添加pulltorefresh

用Intellij IDEA开发Android依赖第三方库和工程

在pulltorefresh里面添加build.gradle文件,把一下代码拷贝进去

apply plugin: 'android-library'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

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

在项目的settings.gradle文件里面添加pulltorefresh工程

include ':app', ':libs:pulltorefresh'

最后在app/build.gradle里面添加这个工程依赖

dependencies {
    compile project(':libs:pulltorefresh')
}


你可能感兴趣的:(用Intellij IDEA开发Android依赖第三方库和工程)