[英]Android override file for flavour
In my android app I have a file that I want to override for a specific flavor.在我的 android 应用程序中,我有一个文件,我想覆盖它以获得特定的风味。 My structure:
我的结构:
However when I build the funki flavour I still see that the Computer class from main is used.但是,当我构建 funki 风格时,我仍然看到使用了 main 中的 Computer class。 In my build.gradle I have:
在我的 build.gradle 我有:
productFlavors {
somename{
resValue "string", "app_name", "some name"
}
funki {
resValue "string", "app_name", "Funki App"
applicationIdSuffix ".funki"
}
}
Every build I see that the Computer file from main is used.我看到的每个构建都使用了 main 中的计算机文件。 All the other overrides e,g, res files are overriden based on the flavor i build.
所有其他覆盖,例如 res 文件都根据我构建的风格被覆盖。 How can I override a class for a specific flavor?
如何覆盖 class 以获得特定风味?
You should be getting a "duplicate class" build error — at least, that used to be the behavior.你应该得到一个“重复的类”构建错误——至少,这是过去的行为。 You cannot override a Java/Kotlin class in a flavor.
您不能以某种方式覆盖 Java/Kotlin class。
What you can do is remove the Java/Kotlin class from the main
source set and have it in all of your flavors.您可以做的是从
main
源代码集中删除 Java/Kotlin class 并将其用于您的所有风格。 So, move Computer.java
from main
to somename
, and keep your other Computer.java
in funki
.因此,将
Computer.java
从main
移动到somename
,并将其他Computer.java
保留在funki
中。
I ended up checking the productflavor inside the code like:我最终检查了代码中的产品风味,例如:
if(BuildConfig.FLAVOR.equals("funki")){
Based on the if/else I execute my desired code.基于 if/else 我执行我想要的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.