Creating demo and full version app based on one code base/project

前端 未结 3 758
别那么骄傲
别那么骄傲 2021-01-03 03:53

I have developed one Android app in one project with Eclipse - it\'s structured (coming from iPhone) so one constant defines whether it\'s the demo or the full version.

3条回答
  •  攒了一身酷
    2021-01-03 04:23

    I'm doing this currently in eclipse, and it is not difficult.

    1. Convert existing source to library project.

    2. Create two new projects, free and paid.

    3. Include the library project in the free and paid projects.

    It's not necessary to have a single Activity or resource inside the free/paid projects. All you need is a manifest for each which referenes the activities from your library. My free and full projects do not currently have a single java, resource, or layout file of any kind, it's just a manifest which references activities from the library.

    I use the exact same code for both projects, and I differentiate them by saying :

    if(getApplicationContext().getPackageName().equals("full version package name")) {
        //do full stuff
    } else {
        //do free stuff
    }
    

    Some gotchas I've hit, especially if you've already released your app on the market:

    • If you change the full name/path of any activity, it will disappear from your homescreen. Therefore if your library has a different package name than the existing version, you will lose any homescreen icons. They can be replaced by the user but it's not ideal.
    • Similar for appwidgets, if you change their receiver name, they will disappear on upgrade.
    • You may not under any circumstance change the package name of a released application.

    If you've already released a free and pro version, it's somewhat unfortunate, because the activity path will need to change to a common library path, and you can't rename the released package to match the library path. So somebody will have to lose their existing icons.

    In my case I had only released a free version before splitting them, and I was able to name the library with the same package name as the free version. I was skeptical that you'd be allowed to include a library with the same package name as the wrapper package, but apparently it's possible to do so (working fine for me).

    So in my case I've got three projects:

    • Core Library: package name : com.myname.myapp
    • Free Version: package name : com.myname.myapp
    • Pro Version: package name : com.myname.myapp.Pro

    And the free and full version manifests add activities which are named com.myname.myapp.ActivityA or com.myname.myapp.ActivityB, which exist only in the library project.

提交回复
热议问题