Picking a specific build type in a dependency

后端 未结 5 2413
闹比i
闹比i 2021-02-20 07:14

Suppose I have an Android app with three build types:

buildTypes {
    release {
        ....
    }
    optRelease {
        ....
    }
    debug {
        ....
         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-20 07:36

    You can use matchingFallback

    buildTypes {
        release {
           matchingFallbacks = ['debug']
           ... 
        }
        optRelease {
           matchingFallbacks = ['release']  
           ...
        }
        debug {
           matchingFallbacks = ['debug']  
           ...
        }
    }
    

    You can also specify list of fallback as follows:

    optRelease {
        matchingFallbacks = ['release','debug']  
    }
    

    This will specify a sorted list of fallback build types that the plugin should try to use when a dependency does not include a "optRelease" build type. You may specify as many fallbacks as you like, and the plugin selects the first build type that's available in the dependency.

    You can refer to official document for more details.

    However if you want to use variant-specific configurations when targeting external dependencies. You can do it as follows:

    debugImplementation project(':myDependency')

    This will make myDependency as a dependency to only the "debug" version of your module.

提交回复
热议问题