Thursday, January 14, 2016

Android studio src/ 下面的路径的含义?

Source directories

To build each version of your app, the build system combines source code and resources from:
  • src/main/ - the main source directory (the default configuration common to all variants)
  • src/<buildType>/ - the source directory
  • src/<productFlavor>/ - the source directory
Note: The build type and product flavor source directories are optional, as Android Studio does not create these directories for you. You should create these directories as you add build types and product flavors to the build configuration files. The build system does not use these directories if they are not present.
For projects that do not define any flavors, the build system uses the defaultConfig settings, the main app directory and the default build type directories. For example, to generate the default debug and release build variants in projects with no product flavors, the build system uses:
  • src/main/ (default configuration)
  • src/release/ (build type)
  • src/debug/ (build type)
For projects that define a set of product flavors, the build system merges the build type, product flavor and main source directories. For example, to generate the full-debug build variant, the build system merges the build type, product flavor and main directories:
  • src/main/ (default configuration)
  • src/debug/ (build type)
  • src/full/ (flavor)
For projects that use flavor dimensions, the build system merges one flavor source directory per dimension. For example, to generate the arm-demo-release build variant, the build system merges:
  • src/main/ (default configuration)
  • src/release/ (build type)
  • src/demo/ (flavor - app type dimension)
  • src/arm/ (flavor - ABI dimension)
The source code from these directories is used together to generate the output for a build variant. You can have classes with the same name in different directories as long as those directories are not used together in the same variant. 
The build system also merges all the manifests into a single manifest, so each build variant can define different components or permissions in the final manifest. The manifest merge priority from lowest to highest is libraries/dependencies -> main src -> productFlavor -> buildType. 
The build system merges all the resources from the all the source directories. If different folders contain resources with the same name for a build variant, the priority order is the following: build type resources override those from the product flavor, which override the resources in the main source directory, which override those in any libraries.
Note: Build variants enable you to reuse common activities, application logic, and resources across different versions of your app.


No comments:

Post a Comment