How to update an imported module in Android Studio?

心不动则不痛 提交于 2019-12-18 10:32:24

问题


While I develop an Android App, I have a library which I have created as separate Android Studio project and can use it by inserting it into new projects. I insert the library by choosing 'File|New|Import Module...' option.

The thing is that after the import, Gradle creates a hard copy of my library. If I change the library code in main external project, the code inside the project which is using the library won't get updated.

How can I have a library and share it among many project? I need to change the library in one single place and then all other projects which are using it get the update.

I found this post also which has no answer:

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


回答1:


OK I found the answer by myself:

You must not add the external library as an existing module. It will make a copy of it under your project folder.

What you have to do is:

1) Delete the library folder in your current project. 2) Open the 'setting.gradle' file and add these:

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

3) In your 'build.gradle' file add dependency as:

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

4) Sync the project and you are done.



来源:https://stackoverflow.com/questions/32579557/how-to-update-an-imported-module-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!