Hello :wave: :slightly_smiling_face: I have a ques...
# android
Hello 👋 🙂 I have a question regarding my android project. Recently I just had App1, but now I need to be able to build another apk (different package name) from the same code base, App2 So, what I did so far is to split up the app in modules like this: com.base se.app1 se.app2 both app1 and app2 depend on base in base i have a file: com.base.Constants.kt in app2 I want to override that file. So app2 also has file com.base.Constants.kt but with different values. When I run both app1 and app2 in debug everything works well! But when I am trying to generate a signed apk for app1 and app2 I get error:
Duplicate jar entry [com/base/Constants.class]
Does anyone know how to deals with this? Can I specify in gradle somehow to now include the Constant.kt in base? Or did I misunderstood how to use modules with multiple apps? Thankful for any answers 🙏 🙏 🙏 FYI: I know that gradle can be used to handle constants but right now I am just using that file to test if this structure of modules is possible
Just move the file base/com.base.Constants.kt into app1/com.base.Constants.kt if you only need it in app1.
Remove it from constants from base it would probably work, but I would suggest to not use a .KT for defining constants
For that it's better to use the xmls files in the res folder
the module base is using Constants. So i can´t move it to app1
Unless you’re doing some logic in this kt file, you should use resources.
Ignore the constants file, it the possibility to override a class that I am looking for 🙂
It’s a flag you can set on a jar build, if you set it to EXCLUDE then it ignores files that are already in the jar. That would mean you would need to first add app1/2 files, then add base files. And in this case base’s Constant file would not be added.
yes @ribesg that is what I am trying to do, like this:
Copy code
packagingOptions {
        exclude 'base/src/main/res/java/com/base/Constants.kt'
But I am not sure how to write and I have not succeeded yet!
do you know how to write the exclude? btw, the module is not a jar, its an android project
If you're using it in the base, then you shouldn't override it in the app2. Make 2 separate configs, one for the base and one for the app2 if you need to
@Rok Koncina thanks for the answer, but I am using the file in the base module, and base module does not depend on app2, so I don´t see how that could work 😕
Consider it from this perspective: if it's constants, then define them as constants and don't override them. If they are configuration, then create some configuration holder class in the base module and then set it's values from app1 and app2
☝️ 1