[英]How to build different flavor apks with different Java code?
I know we can build different flavor apks with different resources by creating different directory within src, but now I want to make some java code customized, is that possible? 我知道我们可以通过在src中创建不同的目录来使用不同的资源来构建不同的口味apk,但是现在我想定制一些Java代码,这可能吗? Or any other ways to do it?
还是有其他方法可以做到?
update 更新
I have a project with 100 *.java files, and I have 10 flavors, but each flavor has only one file is customized and the file in each flavor is not the same file, so I have to put that 10 files in each flavor, and once a file in that 10 files is modified, I will have to modify the same file in other flavors, the project is like: 我有一个包含100个* .java文件的项目,并且我有10种口味,但是每种口味只有一个文件是自定义的,每种口味的文件都不相同,因此我必须在每种口味中放入10个文件,并且一旦修改了10个文件中的一个文件,我将不得不以其他方式修改相同的文件,该项目就像:
+ App |- src |- main |- java |- path |- A.java(can't be here) |- B.java(can't be here) |- C.java(can't be here) |- D.java(can't be here) |- E.java(can't be here) |- F.java(can't be here) |- G.java(can't be here) |- Others.java + res |- flavorA |- java |- path |- A.java(customized) |- B.java |- C.java |- D.java |- E.java |- F.java |- G.java + res |- flavorB |- java |- path |- A.java |- B.java(customized) |- C.java |- D.java |- E.java |- F.java |- G.java + res |- flavorC |- java |- path |- A.java |- B.java |- C.java(customized) |- D.java |- E.java |- F.java |- G.java + res |- flavorD |- java |- path |- A.java |- B.java |- C.java |- D.java(customized) |- E.java |- F.java |- G.java + res |- flavorE |- java |- path |- A.java |- B.java |- C.java |- D.java |- E.java(customized) |- F.java |- G.java + res |- flavorF |- java |- path |- A.java |- B.java |- C.java |- D.java |- E.java |- F.java(customized) |- G.java + res |- flavorG |- java |- path |- A.java |- B.java |- C.java |- D.java |- E.java |- F.java |- G.java(customized) + res
Yes you can use different java class for both different product flavor so your project structurer will be like below image. 是的,您可以对不同的产品风格使用不同的java类,因此您的项目结构器将如下图所示。
It was works for me. 这对我来说很有效。
+ App
|- src
|- main
|- java
|- path
|- A.java
|- B.java
|- C.java
|- D.java
|- E.java
|- F.java
|- G.java
|- Others.java
+ res
|- flavorA
|- java
|- path
|- A.java(customized)
+ res
|- flavorB
|- java
|- path
|- B.java(customized)
+ res
|- flavorC
|- java
|- path
|- C.java(customized)
+ res
|- flavorD
|- java
|- path
|- D.java(customized)
+ res
|- flavorE
|- java
|- path
|- E.java(customized)
+ res
|- flavorF
|- java
|- path
|- F.java(customized)
+ res
|- flavorG
|- java
|- path
|- G.java(customized)
+ res
You have to add file structure as above. 您必须如上所述添加文件结构。 You have to add all the files on main directory and only you need to add modified files as per flavor.
您必须将所有文件添加到主目录中,而仅需要按照风味添加已修改的文件。 If you will put every files in every flavor than in future when you will change A.java than you have to update every A.java of all flavors.
如果您将每个文件放在每个版本中,而将来更改A.java时,则必须更新所有版本的每个A.java。
So its better add all the files on main directory and only you need to add modified files as per flavor . 因此,最好将所有文件添加到主目录中,并且只需要根据风味添加已修改的文件 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.