![](/img/trans.png)
[英]Is it possible to exclude specific build variant when using flavor Dimensions?
[英]Android Gradle declare a Variant Build Flavor dependency using API and Exclude in KTS
我正在嘗試構建我的應用程序的風格,其中包含非常重的依賴項,並且只會在某些構建中用於測試和離線開發(依賴項是 Android 的 Wiremock)。 但是,我似乎找不到任何也使用 api() 和排除的風味變體依賴聲明。
在我決定將依賴項移動到構建變體之前,我可以像這樣聲明依賴項:
dependencies {
//WireMock - Do not put in release builds bc of large size
api("com.github.tomakehurst:wiremock:2.18.0") {
exclude("org.apache.httpcomponents", "httpclient")
exclude("org.ow2.asm", "asm")
exclude("org.json", "json")
}
api("org.apache.httpcomponents:httpclient-android:4.3.5.1")
}
我很想將此依賴限制為我的構建風格,我簡稱為“模擬”,例如:
dependencies: {
"mockImplementation"(
api("com.github.tomakehurst:wiremock:2.18.0") {
exclude("org.apache.httpcomponents", "httpclient")
exclude("org.ow2.asm", "asm")
exclude("org.json", "json")
}
api("org.apache.httpcomponents:httpclient-android:4.3.5.1")
})
}
這顯然是非常錯誤的,但我不確定如何使用 api 格式化 go 並排除依賴符號,因為在將這些與構建風格相結合時,我找不到很多示例。
在玩了很多之后,我最終得到了:
// WireMock - Do not put in release builds bc of large size, restrict to mock flavors
"mockImplementation"(mockApi("com.github.tomakehurst:wiremock:2.18.0") {
// Using Android Version Instead
exclude("org.apache.httpcomponents", "httpclient")
//Was getting a classpath conflict for org.objectweb.asm.AnnotationVisitor which is a part of 'net.minidev:asm'
exclude("org.ow2.asm", "asm")
//Was getting this warning, so decided to ignore this version included by WireMock.
//Warning:Dependency org.json:json:20090211 is ignored as it may be conflicting with the internal version provided by Android.
//In case of problem, please repackage with jar to change the class packages
exclude("org.json", "json")
})
"mockImplementation"(mockApi("org.apache.httpcomponents:httpclient-android:4.3.5.1") {})
請注意,“mockApi”是必要的,而不僅僅是使用“api”來實際約束變體。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.