Hello! I need to compile two different applications from the same source code. These applications differ only in package name and resources.

I wanted to use analogues #ifdef #define , but it turned out that they simply do not exist ...

More specifically, I need to use the resource file (R) of one application in the same source file when compiling an application, and another file for another application.

    5 answers 5

    Everything is very real. There is such a project - antenna, it formally implements the preprocessor. Read how to do and what to download, you can on Habré .

    In several projects I tested, it works quite normally.

    • Thank you very much! Created two batch file for code preprocessing for different applications. In general, it is a pity that there are still no directives in Java ... - Vladyslav Matviienko
    • There is a lot of things in Java yet. And it is unlikely to be. But is this a problem? You can always either pile a crutch, or write the right one. - KoVadim

    You need to add a Java tag and who can help more accurately. I doubt that this is an impossible task (if there is such a thing in the pros ...). Google build systems for Java projects (unfortunately not strong in Java technologies).

      Try to create an Android Library. You take out the resources and code that are repeated and use at least in Google applications.

        Famous rake. The problem is solved in 2 stages:

        1. Instead of #ifdef/#ifndef you should use public static final boolean flag=true/false; . This, of course, is not quite the directives of the preprocessor, but it makes its contribution in terms of reducing the cost of the code, since in the final binary the compiler will still reject the dead branches.
        2. You need to have several manifestos, each of which has its own activator launcher.

        If you really want beauty already, then you can wrap ant script around it to automate switching between branches.

        On the stack I already answered a similar question.

        • if everything was so simple ... the fact is that in the “common” files for two projects I use the link to the resource file (R), and it should be imported from different packages for each application ... - Vladyslav Matviienko nov
        • The resource is generated the same in content, but in different packages. The package is assigned in the manifest. There is a small trick: you need to generate and compile a resource for one app (package) and then use it for another app (package). If you do not rebuild, then everything will work. I have 3 sources generated from some sources: demo, light and full - and everything is fine. I just change manifests without rebuilding resources and that’s it. - Barmaley

        It is unlikely that this will happen, create 2 different projects with different resources.

        If you really want to, throw off all the resources in one folder and just substitute the code with the necessary images depending on the compilation parameter.