如何使用 Gradle/Android Studio 中的外部库项目中的代码修改来更新导入的模块 [英] How to update imported modules with code modification from the their external library project in Gradle/Android Studio

查看:38
本文介绍了如何使用 Gradle/Android Studio 中的外部库项目中的代码修改来更新导入的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm developing an android app, in which I recently migrated from Eclipse to Android Studio and Gradle.

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

In my projected I created 5 UI Libs, and added them as modules in my project, libs I have created are pushed on my github account (publicly).

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

In eclipse when you add external dependency for a project marked as lib, when you update the external project's code then you clean your build, your project get these updates, but in Gradle I noticed that it creates Physical Copies, completely independent from their sources, my question is how can I change only external libs and have my project updated.

这是从我的 gradle 配置中截取的:

here's a snipped from my gradle's config:

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')
    .
    .
}

推荐答案

如何实际使用外部库

我读过不推荐但它对于调试很实用:

How to actually use external libraries

I've read that is not recommended but it is practical for debugging:

  1. 文件 > 项目结构... > 加号以添加模块

  1. File > Project Structure... > PLUS sign to add module

创建新模块"对话框:

  • 选择导入 .JAR/.AAR 包"
  • 查找并选择您的包,但在继续之前复制路径
  • 为您的包裹命名

回到项目结构"对话框:

Back at "Project Structure" dialog:

  • 出现消息Gradle project sync in progress..",但需要单击确定"才能真正开始构建.相反,您可以继续使用依赖项.
  • 选择app"模块,进入依赖项标签,然后加号添加模块依赖
  • 选择您的模块
  • 单击确定"以运行构建.

这确实会在您的 android 项目中创建您的包的副本,但它也会生成所有必要的信息和文件,您可以随时删除该副本或不理会它.

That does create a copy of your package inside your android project but it also generates all necessary information and files, and you can always get rid of the copy or leave it alone.

您的模块已添加到 settings.gradle 文件中:

Your module have been added to the settings.gradle file:

':app', ':module_name'

已为您的模块创建了 build.gradle 文件:

A build.gradle file for your module have been created:

configurations.maybeCreate("default")
artifacts.add("default", file('package.jar'))

并且依赖项已添加到您的:app"的 build.gradle 中:

And the dependency has been added to the build.gradle of your ':app':

compile project(':module_name')

  1. 现在,访问您添加的模块的 build.gradle 文件并粘贴您复制的路径:

configurations.maybeCreate("default")artifacts.add("default", file('X:\Java\Applications\YourApplication\dist\package.jar'))

无论你在哪里编辑你的包,只需清理并构建"它.每当您希望您的应用程序在您的 android 项目外部的包中反映该更新"时,只需同步即可.完成调试后,您可以删除模块、依赖项和旧副本,并将包的最后一个构建版本添加为副本.

Wherever you edit your package, just "Clean & Build" it. Whenever you want your app to reflect that "update" in the package from outside your android project, just sync. When you are done debugging, you can remove the module, the dependency and the old copy, and add the last build of your package as a copy.

这篇关于如何使用 Gradle/Android Studio 中的外部库项目中的代码修改来更新导入的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆