Search code examples
androidgradleandroid-build

What happens if I define a class in a build type and a product flavor?


What happens if I define a Java class for a product flavor for example free and also for a build type for example debug.

If I now build myapp-free-debug.apk with gradle which class is packaged into the apk?


Solution

  • Your question title is different from the question body. What are you trying to mix ? Only build types or build type/flavor?

    In case of build type and flavor, I think you can't even build the project if a class is present in a flavor AND in a build type. You will get a duplicate class error. When you use product flavors, one of the flavor is necessarily included in the project, by definition. So the class variants must be in each product flavors, and not in the build types.

    In case of build types only, that's what I'm trying to do currently, I expected that the build will select the java class from the selected build type, and ignore the one in the main folder but not, I get also a duplicate class error. I asked the question on the adt-dev groups, wait and see...


    EDIT : I had a response from Xavier for my previous question, and by design it's not possible to override a class defined in the main directory. That says, he gave a few workarounds to handle my need. See the link above if interested.