是否可以为 Xcode Target 之类的 Android 项目创建多个目标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9108136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:11:13  来源:igfitidea点击:

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

androidiphonexcodeeclipsetarget

提问by Vinayak Bevinakatti

I worked with iPhone Xcode Tragetto 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?

我使用 iPhone Xcode Traget使用单一代码库创建多个 iPhone 应用程序。我的问题是,是否可以为 Android 项目创建多个目标。如果是,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

Xcode Target:单个项目可以包含一个或多个目标,每个目标产生一个产品(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)

iPhone 有许多产品(App1、App2、App3 等)只有一个项目,现在我可以拥有与此相同的一个 Android 项目和多个产品(App1、App2、App3 等)

Thanks in advance

提前致谢

采纳答案by Vinayak Bevinakatti

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

经过广泛的研究,我意识到Android 库项目将为我的需求提供解决方案

An Android library projectis 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.

一个Android的库项目是持有共享Android源代码和资源开发项目。其他 Android 应用程序项目可以引用库项目,并在构建时将其编译源包含在其 .apk 文件中。多个应用项目可以引用同一个库项目,任何一个应用项目都可以引用多个库项目。

注意:您需要 SDK Tools r14 或更高版本才能使用新的库项目功能,该功能将每个库项目生成到自己的 JAR 文件中。您可以使用 Android SDK 和 AVD 管理器下载工具和平台,如添加 SDK 组件中所述。

? 如果您有多个 Android 项目共有的源代码和资源,您可以将它们移动到一个库项目中,以便更轻松地跨应用程序和版本进行维护。以下是您可以使用库项目的一些常见场景:

? 如果您正在开发使用某些相同组件的多个相关应用程序,请将冗余组件移出其各自的应用程序项目,并在库项目中创建一组可重复使用的相同组件。如果您创建的应用程序同时存在于免费和付费版本中。您将两个版本共有的应用程序部分移动到库项目中。具有不同包名的两个依赖项目将引用库项目并仅提供两个应用程序版本之间的差异。

回答by Qasim

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.

Gradle 构建系统使用构建变体和产品风格的组合来生成具有共享/公共代码库和资源的不同应用程序。

As per Android Developer Reference Site:

根据 Android 开发人员参考站点:

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.

构建系统使用产品风格来创建应用程序的不同产品版本。您应用的每个产品版本都可能具有不同的功能或设备要求。构建系统还使用构建类型将不同的构建和打包设置应用于每个产品版本。每个产品风味和构建类型组合形成一个构建变体。构建系统为应用的每个构建变体生成不同的 APK。

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

现在,对于具有相同代码库的单个项目,可以有两种或多种产品风味,例如(付费风味、免费/演示风味)等。

For more information See Build Variants & Product Flavors Doc

有关更多信息,请参阅构建变体和产品风味文档

回答by Rajdeep Dua

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

在 android 中,单个项目中只有一个构建目标。在安装时使用清单文件中的 minSdkVersion、targetSdkVersion 和 maxSdkVersion 控制反向兼容性

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

另外 android 市场确保如果您的应用程序具有本机代码并且是为 ARM 架构构建的,则它在 x86 设备上不可见

回答by jsaye

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.

此示例来自 Google I/O 的视频(最少 5~):http: //www.google.com/events/io/2011/sessions/android-protips-advanced-topics-for-expert-android- app-developers.html。因此,您应该指定 minSdkVersion 和 maxSdkVersion ,然后控制要启动的活动。