简体   繁体   中英

Is it possible to create multiple targets for Android project like Xcode Target

I worked with iPhone Xcode Traget to create multiple iPhone apps with single code base. My question, is it possible to create multiple targets for Android project. If yes, is it possible with Eclipse?

Edit:

Xcode Target: A single Projects can contain one or more targets, each of which produces one product (App). This has always only one Project in which we can select the specific target and run desired app

iPhone have only one Project for many products (App1, App2, App3 etc), Now can I have same as this, one Android Project and multiple products (App1, App2, App3 etc)

Thanks in advance

A bit late, but for those who still looking for solution:

Gradle Build System uses a Build Variant and combination of product flavors to generate different apps with shared/common code base and resources.

As per Android Developer Reference Site:

The build system uses product flavors to create different product versions of your app. Each product version of your app can have different features or device requirements. The build system also uses build types to apply different build and packaging settings to each product version. Each product flavor and build type combination forms a build variant. The build system generates a different APK for each build variant of your app.

Now one can have two or more product flavors eg (paid flavor, free/demo flavor) etc for one single project with same code base.

For more information See Build Variants & Product Flavors Doc

After a wide research I realized Android Library Project will provide solution for my requirement

An Android library project is a development project that holds shared Android source code and resources. Other Android application projects can reference the library project and, at build time, include its compiled sources in their .apk files. Multiple application projects can reference the same library project and any single application project can reference multiple library projects.

Note: You need SDK Tools r14 or newer to use the new library project feature that generates each library project into its own JAR file. You can download the tools and platforms using the Android SDK and AVD Manager, as described in Adding SDK Components.

• If you have source code and resources that are common to multiple Android projects, you can move them to a library project so that it is easier to maintain across applications and versions. Here are some common scenarios in which you could make use of library projects:

• If you are developing multiple related applications that use some of the same components, you move the redundant components out of their respective application projects and create a single, reuseable set of the same components in a library project. If you are creating an application that exists in both free and paid versions. You move the part of the application that is common to both versions into a library project. The two dependent projects, with their different package names, will reference the library project and provide only the difference between the two application versions.

There is only one build target in android in a single project. Backword compatibility is controlled at install time using minSdkVersion, targetSdkVersion and maxSdkVersion in the manifest file

http://developer.android.com/guide/topics/manifest/uses-sdk-element.html

Also android market make sure that if your app has native code and is built for ARM architecture it is not visible on a x86 device

You can control what version someone has installed and starting one activity or another depending on that. You can use something like this:

private static boolean version= android.os.Build.VERSION.SDK_INT>=android.os.Build.VERSION_CODES.HONEYCOMB;

And then do something like:

 public void onCreate(Bundle savedInstanceState){
 Intent startActivity =null;
 if(version)
            startActivityIntent = new Intent( this, newVersionActivity.class );
 else
         startActivityIntent = new Intent( this, oldVersionActivity.class );

 finish();}

This example is from a video of the Google I/O (min 5~): http://www.google.com/events/io/2011/sessions/android-protips-advanced-topics-for-expert-android-app-developers.html . So you are supposed to specify the minSdkVersion and the maxSdkVersion and then control what which activity to start.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM