During development, you may want to modularize the code you want to use in multiple projects as a library project.
I thought that if the build setting of the main project was debugged, the library project would also be debugged. The library project build settings are always release builds by default.
With this, it is not possible to properly use the processing using BuildConfig in the library project. This time, I will introduce how to match the library project to the project settings of the main unit.
Suppose you have the following project structure.
・ App // Main project ・ Module // Library project
settings.gradle
include ':app', ':module'
build.gradle(app)
//com.android.Recognized as the main project by specifying application
apply plugin: 'com.android.application'
--Abbreviation--
dependencies {
・
・
・
compile project(':module')
・
・
・
}
build.gradle(module)
//com.android.Recognized as a library project by specifying library
apply plugin: 'com.android.library'
The above is the setting when nothing is done.
First, build.gradle of module. Describe publishNonDefault (true).
build.gradle(module)
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
publishNonDefault(true)← Add this
・
・
・
}
Next, app build.gradle Delete the existing complie project (': module') and change as follows.
build.gradle(app)
dependencies {
・
・
・
debugCompile project(path: ':module', configuration: ':debug')
releaseCompile project(path: ':module', configuration: ':release')
・
・
・
}
If you do this, the build settings of the module will switch according to the project of the main unit.
Recommended Posts