Android Studio: Adding a library outside of the project root

大城市里の小女人 提交于 2019-12-05 01:16:04

问题


I have two projects, A and B, and would like to share some code between them via a library project, C. What is the proper way to do this such that:

  1. A and B and C are all in separate projects. (Not in the same directory at all)
  2. Changes to C are used in A or B automatically without re-importing C.

I'm fairly new to Android Studio and I've been running into all sorts of issues here. I really just want to use source code that is located outside the project root. Thanks!


回答1:


This sounds like the question asked (and answered) here.

To sum up Scott Barta's answer:

settings.gradle:

include ':module-custom-lib'
project(':module-custom-lib').projectDir = new File(settingsDir, '../../../libraryProject/workspace/projectSrc')

A's and B's build.gradle:

dependencies {
    compile project(':module-custom-lib')
}

So, assuming a file structure like this:

+-- AndroidStudioProjects
|   +-- CoreLibs
|       +-- app (empty)
|       +-- myJavaCoreLib
|       +-- anotherJavaCoreLib
|   +-- AndroidApp1
|       +-- app
|   +-- AndroidApp2
|       +-- app
|   +-- AndroidApp3
|       +-- app

...the code would be:

settings.gradle:

include ':coreLib'
project(':coreLib').projectDir = new File(settingsDir, '../CoreLibs/myJavaCoreLib')

build.gradle in AndroidApp[1, 2 and 3] (your A's and B's):

compile project(':coreLib')


来源:https://stackoverflow.com/questions/30500662/android-studio-adding-a-library-outside-of-the-project-root

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