Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>IMO your best approach to creating multiple app releases from a single source <em>is</em> to use a library project.</p> <p>I've attempted this recently and it seems to work very well. Although I haven't tried releasing code based on this to Google Play, I've created separate apps which can both run at the same time on a test device, with their own icons.</p> <p>Since separate apps on Android must each have a different package name, the easiest way to configure separate behavior is to test that package name in your library to see if it is presently running within the free or the paid version. That test can be made within a custom Application-derived object defined in the library project; the package name can be obtained there by calling getPackageName().</p> <p>Your free and paid apps, at a minimum, may need only an AndroidManifest.xml file and a few resources (e.g., an application icon that distinguishes free from paid).</p> <p>In the manifest for each of the two apps you will want the application element to have its android.name attribute set to the full path to your custom Application-derived class (as defined in the library). And of course you will want to have the package= attribute of the manifest element itself set to a distinct package that ends in something like .free or .paid, for the respective apps. The activity objects in the manifest can then have an android:name attribute that is set to the proper Activity-derived class in the library (using a full path).</p> <p>The code that enables your paid features will then simply call the methods that test the package in your custom Application object, parse the package name, and decide on that basis whether a paid or free version is running, and then enable or disable the paid features accordingly.</p> <p>There is a very helpful example (although somewhat old, still relevant) with full code, here:</p> <p><a href="https://github.com/donnfelker/FullAndLiteVersionSharedLibrary/blob/master/FooLibrary/src/com/example/foolibrary/FooLibraryApplication.java" rel="nofollow">https://github.com/donnfelker/FullAndLiteVersionSharedLibrary/blob/master/FooLibrary/src/com/example/foolibrary/FooLibraryApplication.java</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload