Why does Gradle build my module in Release mode when the app is in Debug

前端 未结 4 1055
醉话见心
醉话见心 2020-11-28 05:26

I\'m making a new Android project, with the standard \'app\' module, as well as a library project (let\'s call it \'custom_lib\'). In the app

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 05:36

    Put this in your app dependencies:

    dependencies {
        debugCompile project(path: ':custom_lib', configuration: "debug")
        releaseCompile project(path: ':custom_lib', configuration: "release")
    }
    

    and in your library's build.gradle add:

    android {
    
        defaultConfig {
            defaultPublishConfig 'release'
            publishNonDefault true
        }
    
    }
    

    Then the library will be built in the same mode as the app. Contrary to previous revisions of this answer, I've confirmed a flavor is not required on the library (this may be due to Gradle or Android plugin versions - I'm using Gradle 2.14 and Android plugin 2.1.0 and did not require it).

    Edit: You may have trouble if you don't clean/rebuild after modifying the gradle files, as outlined in this answer here.

提交回复
热议问题