1

I'm currently building an app for iPhone, iPad, Android phones and Android tablets.

I'm working with a single code base like from this example.

But as my project is a little bit more complex due to support tablets too, I'm looking to exclude assets that are not used on the device that install the app.

To clarify, my project files/folders structure look like this:

Project root:

  • html (html, JS, Css, images for android & ios project)
    • css
      • style.css
      • style-android-phone.css
      • style-android-tablet.css
      • style-ios-phone.css
      • style-ios-tablet.css
    • images
      • shared
        • [...]
      • phone
        • [...]
      • tablet -[...]
    • js
      • [...]
    • templates (=html templates)
      • phone
        • [...]
      • tablet
        • [...]
  • android (eclipse project)
    • assets
      • www (symlink to ../../html)
    • bin
      • [...]
    • gen
      • [...]
    • libs
      • [...]
    • res
      • [...]
    • src
      • [...]
    • [...]
  • ios (xcode project)
    • CordovaLib
      • [...]
    • My_project
      • Classes
        • [...]
      • Plugins
        • [...]
      • Resources
        • [...]
      • [...]
    • My_project.xcodeproj
    • www (symlink to ../../html)

For example, I don't want that the iphone app contains tablets assets like: html/css/style-android-tablet.css, html/css/style-ios-tablet.css, html/images/tablet/, html/templates/tablet/

currently, the app is kind heavy on iphone (for example) because of useless assets (mainly images).

I tried some ideas like: - using 2 tagets in the xcode project. One for iphone and one for ipad. But files and folders under www in xcode are unable to be set as target membership. Only www can be. - using 2 www directories and 2 targets, but iphone target still include the www that target ipad.

I think that this solution could help me but I don't really understand how to adapt it to my file structure.

So I request your help to find the best and simplier solution for the futur (next projects & releases of existing projects).

In advance, thanks for your help.

Cheers.

Community
  • 1
  • 1
iArnaud
  • 21
  • 4

1 Answers1

1

Here's the approach that I've used in the past to share resources across Android and iOS:

You can use this exact technique to have a shared codebase, but also have platform-specific files. Just add a folder to the www directory (not the shared directory), and put your platform specific CSS files inside of it. Note: in this approach, a subfolder of www is symlinked, not the parent of www.

For having separate CSS files between device form factors it's a little bit more tricky...

One option is to conditionally append <style> elements during application initialization using JavaScript. You can inspect the user agent and the window dimensions, and manually add a <style> element for the appropriate platform and form factor. However, user agent sniffing is generally discouraged b/c it can be easily broken, or fail if a new device category is introduced.

Another option is to include everything and use CSS media queries.

If you are using a universal binary (targets both phone and tablet form factors), then you have to include the phone and tablet CSS both in the app. You can use CSS media queries so that CSS styles are only applied to specific device form factors. So, wrap your tablet styles in a media query, and they will only be applied to the tablet form factor.

You can read more about CSS media queries here:

You can access predefined CSS media queries for common device form factors here:

If you are not using a universal binary, you would need separate project environments for each device category. In each separate project, you could symlink to the shared codebase, with a static path to the CSS file.

If you want to conditionally insert specific CSS files to specific project configurations, then you either need separate projects for each, or you need to write a script to do it for you.

Hopefully that helps...

Community
  • 1
  • 1
Andrew Trice
  • 701
  • 5
  • 8
  • Thanks for your answer Andrew. We already handle css load depending of the device type (using javascript). But my question is more about excluding **tablet images** to be included into the install for iphone, for example. Our phone version of the app is already quite heavy on IOS (~9Mo). So I don't want that once the tablet part would be added to the project that the size grow up to ~30Mo where 20Mo are not used. – iArnaud Dec 14 '12 at 15:32
  • I use the same approach than you to share resources across Android and iOS (I think that, I follow your tutorial for that). But this approach only resolve the problem of separated or shared resources across OS's (Android & IOS) but not for devices type under same OS. I think that for Android, I can extend this approach since Google Play allow to upload 2 different builds for the same app (one target phones, the other that target tablets). But using this approach on IOS (2 IOS projects with symlinks) will force me to have 2 app to manage in the App Store. I would link to avoid that. – iArnaud Dec 14 '12 at 15:32
  • With the universal binary approach for iOS, you unfortunately don't have much choice. If you want it to be inside the app archive for both form factors, then the assets have to be in there. The only alternative I can think of is that you could pull the UI elements from a server and save locally when needed (HTML5 cache or write to local file system). This would reduce IPA file size, but would require downloading assets on first use. – Andrew Trice Dec 14 '12 at 15:47