如何通过Gradle/Android Studio中的外部库项目修改导入的模块并修改代码

She*_*bic 7 android android-studio build.gradle android-gradle-plugin

我正在开发一个Android应用程序,我最近从Eclipse迁移到Android Studio和Gradle.

在我的预测中,我创建了5个UI Libs,并将它们作为模块添加到我的项目中,我创建的库被推送到我的github帐户(公开).

在eclipse中为标记为lib的项目添加外部依赖项时,当您更新外部项目的代码然后清理构建时,您的项目会获得这些更新,但在Gradle中我注意到它创建了物理副本,完全独立于其源,我的问题是如何只更改外部库并更新我的项目.

这是从我的gradle的配置剪切:

dependencies {
    // Libraries
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:5.0.89'
    .
    .
    . 
    compile 'com.squareup.picasso:picasso:2.4.0'

    // Projects
    compile project(':com.shehabic.helpicon')
    .
    .
}
Run Code Online (Sandbox Code Playgroud)

Ehs*_*san 0

您不得将外部库添加为模块。它将在您的项目文件夹下复制它。

你需要做的是:

1) 删除当前项目中的库文件夹。2)打开“seeting.gradle”文件并添加以下内容:

include ':your_external_library_module_name', ':perhaps_second_external_library'

project (':your_external_library_module_name').projectDir = new File('../path/to/your/external/library')
project (':perhaps_second_external_library').projectDir = new File('../path/to/your/second/external/library')
Run Code Online (Sandbox Code Playgroud)

2)在“build.gradle”文件中添加依赖项:

dependencies {
    compile project(':your_external_library_module_name')
    compile project(':perhaps_second_external_library')
}
Run Code Online (Sandbox Code Playgroud)

3) 同步项目即可完成。