How to setup Android Library module and be referenced by multiple projects in Android Studio?

后端 未结 2 1997
轻奢々
轻奢々 2021-02-06 04:52

My company is making several Android projects on Android Studio, which all of them share some similar codes, such as custom views, customised HTTP clients, and many other things

相关标签:
2条回答
  • 2021-02-06 05:33

    Refer these Links

    How to create a library project in Android Studio and an application project that uses the library project

    http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Multi-project-setup

    0 讨论(0)
  • 2021-02-06 05:44

    Our company used a structure with multiple projects with shared modules. Suppose you have 2 projects, project1 and project2 which are 2 independent Android Studio projects and want to share some modules. The folder structure will be like this:

    source-code-root-folder/
        + android-studio-project1/
             + project1-app-module/
             + project1-internal-module/
        + android-studio-project2/
             + project2-app-module/
             + project2-internal-module/
        + shared-module1/
        + shared-module2/
    

    You can first create the projects and modules from Android studio. Then relocate the folders like the structure above. Then update the setting in project1 by putting this settings in the source-code-root-folder/android-studio-project1/settings.gradle:

    include ':android-studio-project1'
    include ':project1-app-module'
    include ':project1-internal-module'
    include ':..:shared-module1'
    include ':..:shared-module2'
    

    Then open the android-studio-project1/project1-app-module/build.gradle and update the dependencies:

    ...
    dependencies {
        ...
        compile project(':project1-internal-module')
        compile project(':..:shared-module1')
        compile project(':..:shared-module2')
    }
    

    This will make project1 be able to load the internal module and the shared modules as well. Try sync and build your project1 by running build.gradle in the project1 and it should work. Of course similar setting can be used for the project2.

    Hope that this can help you.

    0 讨论(0)
提交回复
热议问题