Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Ti.include: Differences Between Android and iPhone


I want to include some device-specific constants in all of my JavaScript files. I thought the easiest way to do this would be to put the constants in the /Resources/android and /Resources/iphone directories, and include them using Ti.include() as needed.

I created two device specific constant files:


I have a /Resources/login/login.js file. To include the device.js file, I thought I could use this line in the login.js file:


This works on Android; the /Resources/android/device.js file is included. However, on iPhone, it complains that it can't find the device.js file. To get the include to work on iPhone, I had to use this line:


Which obviously is not cross-platform.

My question: How I can include device specific files in a cross-platform way? Am I doing something wrong or did I encounter a bug? If it's a bug, is there any work around you can suggest?

Thank you!!!


— asked June 7th 2010 by Ryan Asleson
  • include

3 Answers

  • I can't get any combination of path to work with Ti.include on android, only iphone. Even with what your example shows.

    For your question, have you tried wrapping each include path syntax with:

    if (Ti.Platform.osname == "iphone"){
    //include one way
    } else if (Ti.Platform.osname == "android"){
    //include the other way

    I've been using that conditional syntax to do various platform specific things.

    — answered June 17th 2010 by Andrew Blair
  • One issue that I've been having is that when building for android, the javascripts are not getting copied to the Resources folder.
    It only happens with a few javascript files. If I manually copy the js files to the build folder then the includes work.
    I find that the android support in Titanium is light years behind the iphone support.

    — answered February 1st 2011 by Daniel Tome
  • This worked perfectly fine on 1.6, upon upgrading to 1.7 I have found this problem too.
    Is this a bug or a feature?

    — answered October 11th 2011 by Marc Wickens
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.