Require Gradle project from another directory

后端 未结 3 746
温柔的废话
温柔的废话 2020-12-04 10:34

I have a directory/project setup like this:

C:\\
    _dev\\
        Projects\\
            Logger
            MyProject

Logger is

相关标签:
3条回答
  • 2020-12-04 11:13

    Try adding the dependency to the global "dependencies" section, not the "android > dependencies". During development, the "android" configuration is used, but not to package the runtime.

    dependencies {
        compile 'com.android.support:gridlayout-v7:18.0.0'
        compile 'com.android.support:appcompat-v7:18.0.0'
        compile files("../Logger")
    }
    

    It may also be worthwhile to look into setting up a multi-project gradle configuration, with a build.gradle and settings.gradle in the shared parent directory like here: http://www.gradle.org/docs/current/userguide/multi_project_builds.html

    0 讨论(0)
  • 2020-12-04 11:14

    Android Studio 2.2.3:

    Add to settings.gradle.

    include ':app', ':new_lib'
    project(':new_lib').projectDir = new File('../new_lib/app')
    
    • The path must be relative from the root of the project you're working on.
    • The module you're referencing must have a reference to it's "app" directory.

    Then edit your Project Structure | Modules to setup dependencies.

    0 讨论(0)
  • 2020-12-04 11:24

    The simplest way is to make MyProject a multi project with the Logger project as a subproject.

    settings.gradle in MyProject directory:

    include ":logger"
    project(":logger").projectDir = file("../logger")
    

    In the build.gradle of MyProject you can now reference this lib as a project:

    dependencies {
         compile 'com.android.support:gridlayout-v7:18.0.0'
         compile 'com.android.support:appcompat-v7:18.0.0'
         compile project(":logger")
    }
    
    0 讨论(0)
提交回复
热议问题