Gradle中的Settings和SourceSet

文章目录

  • Settings
  • SourceSet

Settings

Settings 的核心作用就是决定我们项目的哪些工程是要被gradle处理的。

Settings.java部分源码:

@HasInternalProtocol
public interface Settings extends PluginAware, ExtensionAware {
    /**
     * 

The default name for the settings file.

*/
String DEFAULT_SETTINGS_FILE = "settings.gradle"; /** *

Adds the given projects to the build. Each path in the supplied list is treated as the path of a project to * add to the build. Note that these path are not file paths, but instead specify the location of the new project in * the project hierarchy. As such, the supplied paths must use the ':' character as separator (and NOT '/').

* *

The last element of the supplied path is used as the project name. The supplied path is converted to a project * directory relative to the root project directory. The project directory can be altered by changing the 'projectDir' * property after the project has been included (see {@link ProjectDescriptor#setProjectDir(File)})

* *

As an example, the path {@code a:b} adds a project with path {@code :a:b}, name {@code b} and project * directory {@code $rootDir/a/b}. It also adds the a project with path {@code :a}, name {@code a} and project * directory {@code $rootDir/a}, if it does not exist already.

* *

Some common examples of using the project path are:

* *
     *   // include two projects, 'foo' and 'foo:bar'
     *   // directories are inferred by replacing ':' with '/'
     *   include 'foo:bar'
     *
     *   // include one project whose project dir does not match the logical project path
     *   include 'baz'
     *   project(':baz').projectDir = file('foo/baz')
     *
     *   // include many projects whose project dirs do not match the logical project paths
     *   file('subprojects').eachDir { dir ->
     *     include dir.name
     *     project(":${dir.name}").projectDir = dir
     *   }
     * 
* * @param projectPaths the projects to add. */
void include(String... projectPaths);

最重要的就是include方法,将我们新建的子工程引入进来,这样gradle才会把它当做一个工程去处理。

gradle的初始化阶段就完成在执行settings.gradle中的内容


SourceSet

SourceSet决定了代码、资源、第三方库等要存放的位置

约定:
java目录–>
res目录–>

gradle-core-2.2.2.jar / com / android / build / gradle / api /AndroidSourceSet.class

gradle-core-2.2.2.jar / com / android / build / gradle / api /AndroidSourceDirectorySet.class


资源文件分模块
创建两个资源文件夹res-ad和res-player

在app的build.gradle中修改sourceSets

  sourceSets {
        main {
            jniLibs.srcDirs = ['libs'] //修改so库存放位置

            res.srcDirs = ['src/main/res',
                           'src/main/res-ad',
                           'src/main/res-player']
        }
    }

你可能感兴趣的:(Gradle)