Multiple Android Application Package .apk files from single source code

后端 未结 10 945
我在风中等你
我在风中等你 2020-12-02 06:29

I would like an Android build system procedure, command line or Eclipse, to generate several .apk files from a single source codebase. Some common reasons for this - having

相关标签:
10条回答
  • 2020-12-02 07:09

    This article has a good walk-through with examples of how to amend config files at build time; see in particular the Customizing the build and Using a Java configuration file sections. Note that some of the information about build.xml and ant is a little bit out-of-date now.

    0 讨论(0)
  • 2020-12-02 07:13

    It's easily to achieve your goal by using Android Studio build variants which use graddle as the build system.

    Check here for more detailed information.

    0 讨论(0)
  • 2020-12-02 07:17

    I'm generating 2 different APK's (demo and production) from one single source tree with 3 small modifications:

    1) I have public static final DEMO=true; //false; in my Application class and depending on that value I used to switch code between demo/production features

    2) There are 2 main activities, like:

    package mypackage;
    public class MyProduction extends Activity 
    {
        //blah-blah
    }
    
    package mypackage.demo;
    public class MyDemoActivity extends mypackage.MyProductionActivity
    {
        //blah-blah
    }
    

    3) And in the end 2 separate AndroidManifest.xml files which points to different launcher activities depending on demo/production switch

    I'm switching between 2 APK's manually, but see nothing difficult in writing small ANT task to switch between them automatically

    0 讨论(0)
  • 2020-12-02 07:19

    The answer to this screams Gradle, as explained on this website. It's officially built into Android Studio and is encouraged.

    It's amazing; I've built 3 separate apps using the same source code, with customized text and graphics, with no special coding whatsoever. Just some directory and Gradle setup is required, and other posts of mine can be found with answers to both.

    It seems to explain all the basics really well. For the answer to your specific question, look for the section Product Flavors under Build Variants, where it describes specifying different flavors.

    As the website explains, part of the purpose behind this design was to make it more dynamic and more easily allow multiple APKs to be created with essentially the same code, which sounds exactly like what you're doing.

    I probably didn't explain it the best, but that website does a pretty good job.

    0 讨论(0)
提交回复
热议问题