javaandroidshared-librariesmultiple-apk

How to make lite/pro versions of app function slightly different from the referenced library


Right now I have 3 projects:

  1. Library with all my code
  2. Pro empty shell
  3. Lite empty shell

I need to be able to do four things:

  1. Change an int in library based on if user has pro or lite version
  2. Change a long in library based on if user has pro or lite version
  3. Add ads in the lite shell
  4. Change the launch icon. Not sure where to put this. Leave both icons out of library or put both in library?
  5. I have 2 Google Analytic codes -- one to track pro and other to track lite
  6. I have a TextView in library right now that has a link to the pro version. Should I leave this in the library or just make it not visible in the pro or take it out the library and only have it in the lite?

I am having trouble finding a good example of how to set up code for this sort of thing. Do I just put logic statements somewhere in the library or do I create some java/xml files in the shells? So right now the empty pro/lite projects just reference the library but have no jars, xml files, java files, pngs or anything else. I have changed the two shells AndroidManifest package name to be unique to each project.


Solution

  • How about creating an Enum?

    public enum LibType
    {
      PRO(
        0,
        1L,
        "PRO"
      ),
      LITE(
        10,
        20L,
        "LITE"
      );
    
      public final int intVal;
      public final long longVal;
      public final String analyticsCode;
    
      ...
    
      private LibType(
          int intVal,
          long longVal,
          String analyticsCode
        )
      {
        this.intVal = intVal;
        ...
      }
    }