How to create multiple Android apps from one code base

后端 未结 5 1794
醉梦人生
醉梦人生 2021-02-05 06:40

I have an Android code base which uses APIs with settings to get different data for several apps. All apps use the same code base but with one or two design tweaks. So how do I

相关标签:
5条回答
  • 2021-02-05 06:50

    The Android documentation recommends another approach if there aren't too many "different APIs" used.

    The idea is to use reflection instead of making direction references to the code. Make sure to use optimized reflection instead of lookups every time.

    References

    • http://developer.android.com/training/multiple-apks/api.html
    • http://developer.android.com/google/play/publishing/multiple-apks.html#ApiLevelOptions
    0 讨论(0)
  • 2021-02-05 06:51

    Note: This answer is basically obsolete now that one can create .aar libraries with resources. It still works, though, and there may be times when the portability of a .jar is desirable, so I'm leaving it here.

    Blumer's answer is a good one, and you should definitely look into Android's idea of library projects. However, there is another alternative. If you have a module that contains only Java code, but no resources of any kind (images, layouts, etc.), you can compile it to a .jar file separately and use the resulting .jar in multiple application projects. It works like this:

    • Create a new Java project in Eclipse (not an Android project) and move the source code of your module there.
    • If your module references any classes from the SDK, you'll need to add the Android SDK .jar to the project's classpath (Project > Properties > Java Build Path > Libraries > Add JAR).
    • When your module is ready to use, bundle up its .class files into a .jar. You can do this manually, or you can look around to figure out how to get Eclipse to do it for you.
    • Copy your module .jar file into the "libs" directory of your app's main project.
    • Add the module .jar to the project's classpath (again, Project > Properties > Java Build Path > Libraries > Add JAR).

    Now you should be able to build multiple apps using the same .jar, while maintaining only one copy of the module's source code.

    Depending on your particular situation, this may or may not work any better for you than the standard Android library mechanism. But it's worth considering as an alternative.

    0 讨论(0)
  • 2021-02-05 07:04

    You might want to consider using a source control system like Subversion (or GIT). Keep your most feature complete version in the trunk, and make branches for your separate versions that use different data sources or require minor layout changes, etc.

    0 讨论(0)
  • 2021-02-05 07:13

    Check out "Working With Library Projects" from the Android documentation. This should be just what you're looking for: http://developer.android.com/tools/projects/projects-eclipse.html#SettingUpLibraryProject

    0 讨论(0)
  • 2021-02-05 07:13

    The current way to approach this issue if you are using Android Studio with Gradle is by using Gradle, Build Type + Product Flavor

    http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants

    Build Variants

    One goal of the new build system is to enable creating different versions of the same application.

    There are two main use cases:

    Different versions of the same application For instance, a free/demo version vs the “pro” paid application.

    Same application packaged differently for multi-apk in Google Play Store.

    This new concept is designed to help when the differences are very minimum. If the answer to “Is this the same application?” is yes, then this is probably the way to go over Library Projects.

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