Eclipse:来自单一来源的多个项目 [英] Eclipse: multiple project from single source

查看:20
本文介绍了Eclipse:来自单一来源的多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

起初我不得不说我的英语不是很好,所以如果我能很好地解释我的意思,我很抱歉:)

我有一个项目需要复制 n 次;每个新项目必须具有相同的源代码,但不同的资源(例如:图像、html 文件、声音、pdf 等)和不同的类/包名称.

我的项目不是标准的java,而是android+phonegap.我有一个 eclipse 插件可以创建一个空的 phonegap 项目……也许有办法修改这个插件来创建我的标准项目?

有可能吗?最好的办法是也有一个系统可以将主项目中的源代码更改提交给孩子,但这不是强制性的.

再次对不起我的英语.

对不起,如果我再次编辑这个问题,但我真的找不到解决我的问题的方法.

我想结合一个例子,也许我可以解释我需要什么.

想象一下,您已经开发了带有 eclipse 和 phonegap 的 Android 应用程序,例如巴塞罗那足球队.

应用主要是html+jquerymobile,但是你修改了activity,android manifest,添加了一些phonegap插件,一些媒体资源等.

现在你必须为更多的团队复制这个应用程序,很多团队.对于每个人,您必须创建一个新的 phonegap 项目、修改每个文件、添加插件、添加资产......这些任务不可能没有错误.

但最大的问题是:如果你的代码只有一点点更新,你如何在 10/20/50/100/1000 个项目中复制它?

为了更具体,我还在帖子中添加了 android、phonegap 和 cordova 标签.

再次对不起我的英语.

编辑 N°2

我刚刚玩了一个多星期的 maven android 插件,但没有成功.我需要的是集中式代码,我可以在其中切换应用程序和包名、图标和少量配置文件.

Android libs 不是解决方案,因为它无法导出资产文件.

我开始悬赏这个问题寻找详细的答案...请帮忙:(

解决方案

从维护的角度来看,我不会考虑基于相同的代码库复制 1000 个项目.我将使用单个项目管理特定于客户的资源并在项目构建阶段交换所需的资源.换句话说,1 个项目构建 1000 个 apk,而不是 1000 个项目构建 1000 个 apk.

根据您在问题中提供的详细信息,解决这种使用场景(从单一源代码库构建多个应用程序)的正确方向(据我所知)是采用外部构建工具,如 Ant 或Maven 主导构建过程(两者都提供了在完整构建生命周期中对每个步骤进行精细控制的能力,即编译、dex、打包等),并且可能会在需要时编写用于批量构建的 shell 脚本.

我不喜欢 PhoneGap,但可以快速浏览一下它的入门指南,基础据我了解,它只是在 Android SDK 之上的另一个编程层堆栈,提供主要使用 Web 编程语言(HTML、CSS、Javascript)编写移动应用程序的能力,应用程序仍然保留原始项目骨架,所以我不会编写 Ant/Maven 脚本来构建 PhoneGap 应用程序会遇到很多麻烦.

一旦您通过 Maven 成功构建了 PhoneGap 应用程序.您可以开始研究如何解决您的场景,我之前在 StackOverflow 中见过类似的场景,请查看 此线程此线程案例分析.您可以启动概念验证项目以进行可行性研究.

我已经发布了一些示例代码,展示了 Maven 如何实现这一点,见下文.

示例项目目录结构:

myApp/来源/巴塞罗那/资产-巴塞罗那/皇家马德里/资产-realmadrid/……项目.属性AndroidManifest.xmlpom.xml

示例 pom.xml 文件:

<个人资料><id>巴塞罗那</id><属性><app.package.name>com.company.app.barcelona</app.package.name><app.res.dir>${project.basedir}/res-barcelona</app.res.dir><app.assets.dir>${project.basedir}/assets-barcelona</app.assets.dir></属性></个人资料><个人资料><id>皇马</id><属性><app.package.name>com.company.app.realmadrid</app.package.name><app.res.dir>${project.basedir}/res-realmadrid</app.res.dir><app.assets.dir>${project.basedir}/assets-realmadrid</app.assets.dir></属性></个人资料>……</个人资料>....<插件><插件><groupId>com.jayway.maven.plugins.android.generation2</groupId><artifactId>android-maven-plugin</artifactId><version>3.1.1</version><extensions>true</extensions><配置><平台>13</平台></sdk><undeployBeforeDeploy>true</undeployBeforeDeploy><renameManifestPackage>${app.package.name}</renameManifestPackage><resourceDirectory>${app.res.dir}</resourceDirectory><assetsDirectory>${app.assets.dir}</assetsDirectory></配置></插件>……</插件>

要构建 app-barcelona.apk,请运行 mvn clean install -Pbarcelona.
要构建 app-realmadrid.apk,请运行 mvn clean install -Prealmadrid.
要构建其他 1000 个 apk,请编写 shell 脚本.

Android Maven 插件提供了许多配置,让您可以在每个阶段/目标中精细控制构建过程.查看项目文档了解完整详情.>

at first i have to say that i'm not very good with english, so i'm sorry if i can explain very well what i mean :)

I have one project that i need to replicate n times; every new project must have the same source code, but different resources (ex: images, html files, sounds, pdf, etc) and different class/packages names.

my project is not a standard java, but android + phonegap. I have an eclipse plugin that create an empty phonegap project... maybe there is a way to modify this plugin to create my standard project?

Is it possible? The best is to have also a system to commit source changes form the main project to the childs, but it's not mandatory.

Sorry again for my english.

EDIT:

Sorry if i edit again this question, but really i can't find a solution for my problem.

I want to integrate it with an example, maybe i can explain what i need.

imagine you have developed and android application with eclipse and phonegap, for a football team, example Barcelona.

The app mainly is in html + jquerymobile, but you have modified the activity, the android manifest, added some phonegap plugins, some media resource, etc.

Now you have to replicate this app for more teams, a lot of teams. For everyone you have to create a new phonegap project, modify every single file, add the plugins, add the assets.... those tasks can't be error free.

But the very big problem is: if you have only a little update in your code, how you can replicate it over 10/20/50/100/1000 projects?

I've added android, phonegap and cordova tags too to the post to be more specific.

Sorry again for my english.

EDIT N°2

I just played with maven android plugin for over a week now, without success. What i need is centralized code where i can switcch the app and packagename, the icons, and just little configuration files.

Android libs is not a solution, because it can't export assets files.

I started a bounty for this question looking for a detailed answer... please help :(

解决方案

From maintenance perspective, I would not consider replicating 1000 projects base on same code base. I would use a single project manage customer-specific resources and swap the required resource at project build phase. In another word, 1 project to build 1000 apks, not 1000 projects to build 1000 apks.

Based on the details you have given in the question, the right direction (as far as I can see) to solve this kind of use scenario (build multiple applications from single source base) is to adopt external build tools like Ant or Maven dominate build process (both provide the ability to fine-control on every single step i.e. compile, dex, package and etc. during the complete build life cycle) and perhaps write shell script for batch build if needed.

I am not a fun of PhoneGap but have a quick look through its Get Started Guide, base on my understanding, it is just another programming layer stack on top of Android SDK, to provide ability to write mobile app by mainly using web programming language (HTML, CSS, Javascript), the application still keep the original project skeleton so I would not expect much trouble to write Ant/Maven script to build the PhoneGap app.

Once you have successfully built your PhoneGap app by Maven. You can start investigating how to solve you scenario, I have seen similar sort of scenario before in StackOverflow, check out this thread and this thread for some case study. You can start a Proof of Concept project for feasibility study.

I've posted some sample code shows how Maven achieve this, see below.

Sample Project directory structure:

myApp/
  src/
  res-barcelona/
  assets-barcelona/
  res-realmadrid/
  assets-realmadrid/
  ... ...
  project.properties
  AndroidManifest.xml
  pom.xml

Sample pom.xml file:

<profiles>
  <profile>
    <id>barcelona</id>
    <properties>
      <app.package.name>com.company.app.barcelona</app.package.name>
      <app.res.dir>${project.basedir}/res-barcelona</app.res.dir>
      <app.assets.dir>${project.basedir}/assets-barcelona</app.assets.dir>
    </properties>
  </profile>
  <profile>
    <id>realmadrid</id>
    <properties>
      <app.package.name>com.company.app.realmadrid</app.package.name>
      <app.res.dir>${project.basedir}/res-realmadrid</app.res.dir>
      <app.assets.dir>${project.basedir}/assets-realmadrid</app.assets.dir>
    </properties>
  </profile>
  ... ...
</profiles>

....

<plugins>
  <plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <version>3.1.1</version>
    <extensions>true</extensions>
    <configuration>
      <sdk>
        <platform>13</platform>
      </sdk>
      <undeployBeforeDeploy>true</undeployBeforeDeploy>
      <renameManifestPackage>${app.package.name}</renameManifestPackage>
      <resourceDirectory>${app.res.dir}</resourceDirectory>
      <assetsDirectory>${app.assets.dir}</assetsDirectory>
    </configuration>
  </plugin>
  ... ...
</plugins>

To build app-barcelona.apk, run mvn clean install -Pbarcelona.
To build app-realmadrid.apk, run mvn clean install -Prealmadrid.
To build other 1000 apks, write shell script.

Android Maven Plugin provides many configuration let you fine-control build process at every single phase/goal. Check out Project Documentation for full details.

这篇关于Eclipse:来自单一来源的多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆