简体   繁体   English

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

[英]How to update imported modules with code modification from the their external library project in Gradle/Android Studio

I'm developing an android app, in which I recently migrated from Eclipse to Android Studio and Gradle. 我正在开发一个Android应用程序,我最近从Eclipse迁移到Android Studio和Gradle。

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

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

here's a snipped from my gradle's config: 这是从我的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')
    .
    .
}

How to actually use external libraries 如何实际使用外部库

I've read that is not recommended but it is practical for debugging: 我读过这是不推荐的,但它对调试很实用:

  1. File > Project Structure... > PLUS sign to add module 文件>项目结构...> PLUS标志添加模块

  2. "Create New Module" dialogs: “创建新模块”对话框:

    • Select "Import .JAR/.AAR Package" 选择“导入.JAR / .AAR包”
    • Find and select your package but copy the path before continue 查找并选择您的包,但在继续之前复制路径
    • Name your package 为您的包裹命名
  3. Back at "Project Structure" dialog: 返回“项目结构”对话框:

    • The message "Gradle project sync in progress.." appears, but it takes to click OK for the build to actually start. 出现“正在进行Gradle项目同步...”消息,但是单击“确定”以使构建实际启动。 Instead, you can continue with the dependency. 相反,您可以继续使用依赖项。
    • Select "app" module, go to DEPENDENCIES tab, and PLUS sign to add MODULE DEPENDENCY 选择“app”模块,转到DEPENDENCIES选项卡,然后选择加号以添加MODULE DEPENDENCY
    • Select your module 选择你的模块
    • Click OK for the build to run. 单击“确定”以运行构建。

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. 这确实会在您的android项目中创建一个包的副本,但它也会生成所有必要的信息和文件,您可以随时删除副本或不管它。

Your module have been added to the settings.gradle file: 您的模块已添加到settings.gradle文件中:

':app', ':module_name'

A build.gradle file for your module have been created: 已创建模块的build.gradle文件:

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

And the dependency has been added to the build.gradle of your ':app': 并且依赖项已添加到“:app”的build.gradle中:

compile project(':module_name')
  1. Now, access the build.gradle file of your added module and paste the path you copied: 现在,访问添加的模块的build.gradle文件并粘贴您复制的路径:

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

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. 每当您希望您的应用程序从Android项目外部反映包中的“更新”时,只需同步即可。 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. 完成调试后,可以删除模块,依赖项和旧副本,并将包的最后一个版本作为副本添加。

You must not add the external library as a module. 您不能将外部库添加为模块。 It will make copy of it under your project folder. 它将在项目文件夹下复制它。

What you have to do is: 你要做的是:

1) Delete the library folder in your current project. 1)删除当前项目中的库文件夹。 2) Open the 'seeting.gradle' file and add these: 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')

2) In your 'build.gradle' file add dependency as: 2)在'build.gradle'文件中添加依赖关系:

dependencies {
    compile project(':your_external_library_module_name')
    compile project(':perhaps_second_external_library')
}

3) Sync the project and you are done. 3)同步项目,你就完成了。

Do NOT add a module using Studio's "Open Module Settings". 请勿使用Studio的“打开模块设置”添加模块。

Just add the full path of your library's AAR file in your child app's build gradle: 只需在子应用程序的构建gradle中添加库的AAR文件的完整路径:

implementation files('/workspace/AndroidAppsBase/base_app/build/outputs/aar/base_app-debug.aar') 实现文件('/ workspace / AndroidAppsBase / base_app / build / outputs / aar / base_app-debug.aar')

When you make changes to your library project and rebuild the project, a new .aar file will be created. 当您对库项目进行更改并重建项目时,将创建一个新的.aar文件。 To reflect the change in your child project just rebuild it. 要反映子项目中的更改,只需重建它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从导入的库访问项目中的jar-gradle / android studio - access jar in project from imported library - gradle / android studio 如何在Android Studio中编辑使用Gradle导入的库的代码? - How to edit the code of a library imported with Gradle in Android Studio? Android Studio Gradle外部库项目 - Android Studio Gradle External Library Project 如何在Android Studio中更新库项目代码? - How to update a library project code in Android Studio? 如何将Zxing库集成到从Eclipse导入的Android Studio项目中 - How integrate Zxing library into Android Studio project that is imported from Eclipse 我如何从Library Project Android Studio获得收益 - How can I make a gradle from a Library Project Android Studio 如何在Android Studio中的jar中更新外部库 - How to update an external library in a jar in Android Studio Gradle 3,如何使库对Android Studio 3中的其他模块可见? - Gradle 3, how to make a library visible to other modules in Android Studio 3? 如何使用 Android Studio + Gradle + NDK 构建外部 C++ 库? - How to build external C++ library with Android Studio + Gradle + NDK? 如何在我的Android Studio项目的SVN中存储Gradle的外部依赖关系? - How to store the external dependencies of Gradle in SVN for my Android Studio Project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM