Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
181 views
in Technique[技术] by (71.8m points)

android - Eclipse: multiple project from single source

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 :(

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...