23

I am working on a PhoneGap app that is supposed to run on iOS and Android. My folder structure looks like this:

+-+-[app folder]
  |
  +-[android] (contains Eclipse workspace and project files)
  |
  +-[iOS] (contains XCode project files)
  |
  +-[www] (contains all html, js, css etc. files for the actual app)

It's easy to reference the www folder in the XCode project, everything there works fine.

However, creating a link to the www folder in Eclipse doesn't work as expected: I used 'Import -> Filesystem' to create the link under the existing assets folder and everything seemed to work fine. But the files are not getting copied to the apk during the build step.
Any idea what I am doing wrong?

sne11ius
  • 726
  • 1
  • 9
  • 18
  • Were you successful with answer you've marked as accepted? For me it seems 'www' has to be put into '$PROJECT_DIR', otherwise I get infinite number of alert views. – matm Apr 26 '12 at 20:11

3 Answers3

15

This can be accomplished creating a "Linked Folder" resource in Eclipse. It's essentially the same thing as what Xcode creates when you drag any file or folder into your project and tell it to create references - just nowhere near as easy.

The ADT Eclipse plugin expects an "assets" folder at the top level of your project, so we're going to create an /assets linked folder that references ../www, sitting right next to your project folder.

  1. File menu > New > Folder
  2. Folder name: assets
  3. Click Advanced >>
  4. Select: Link to alternate location (Linked Folder)
    • You can use Browse to select the www folder and you're done, but this option creates the link using a full path which will usually break on other team members' systems
  5. Click Variables...
  6. New
    1. Name: SIBLING_WWW_FOLDER
    2. Location: ${PROJECT_LOC}/../www
  7. OK
  8. Select SIBLING_WWW_FOLDER and click OK
  9. Finish
phatblat
  • 3,804
  • 3
  • 33
  • 31
  • Didn't the poster do this? Just in another way. – Greg Randall Nov 16 '11 at 01:59
  • 2
    This doesn't work for me. It works fine for editing, but I don't think that the Android build tools follow the Eclipse links when they bundle the assets into the .apk file. – Paul Beusterien Jan 06 '12 at 17:13
  • This didn't work for me either. The files are not getting bundled in the apk file. Must be some other setting.. :-( Any help is greatly appreciated. – user906825 Jan 10 '12 at 23:26
  • Didn't work for me either. As the files are not copied in the .apk, I found that the mklink /D option in windows works well. – dhaval Feb 16 '12 at 07:04
  • Also didn't work for me! I can't find a setting to get it to work. :-\ – Ricket Feb 18 '12 at 01:42
  • it does work when you try to link assets to ../www. It doesn't when a link is done between assets/www and ../www – Romain Piel Apr 12 '12 at 13:13
  • 1
    For all of those that doesn't work it. You just **cut/move** your current assets folder and **paste** it in ../, rename it (if you want follow step by step the answer) as www and then **follow all the steps**. It does work and it's great when you work with a team using control version. – gergonzalez Apr 27 '12 at 15:18
  • 1
    Yep, does not work as written in the answer. The comments suggesting possible workarounds are not clear enough to follow. – aroth Oct 23 '12 at 04:18
  • Worked for me after adjusting in res/xml/config.xml. Btw, the linked resource is saved in the .project file so this will have to be added to version control if collaborators are to benefit from it. – Torleif Jun 25 '13 at 10:35
  • This worked for me. The key is: 1. Make assets folder itself a link (not make a subfolder of assets a link). 2. Clean the project and/or delete the bin/apk file. Maybe restart eclipse too just to be sure. – Chanon Oct 27 '15 at 19:22
9

For windows use this command mklink /D link-name target-folder and for linux/mac use ln to create a source link. Both works for me.

dhaval
  • 7,611
  • 3
  • 29
  • 38
  • 1
    I had to do it in a Windows command prompt with administrator privileges to have it working properly. – Julien Bérubé Jul 09 '12 at 19:37
  • @JulienBérubé yes i forgot to mention that part, thanks for that. – dhaval Jul 10 '12 at 06:26
  • 2
    A solution that doesn't involve mucking around in the filesystem outside of Eclipse would be far preferable. Does one exist? – aroth Oct 23 '12 at 04:22
  • Dying out here - no cleaner solution yet? – danjah Feb 21 '13 at 09:21
  • @Danjah haven't tried anything as this works fine. Do you have any specific issues?? – dhaval Feb 21 '13 at 09:46
  • @dhaval Only that when imaging a new machine it's another specific thing I have to do in the fs, whereas an Eclipse solution that might apply to many or no projects, or be part of a project config, is what I'd hoped for. I'm new to Eclipse, and so I read this just now: http://www.eclipse.org/forums/index.php/m/771437/ -- does this sound like an alternative do you think? – danjah Feb 21 '13 at 10:31
  • @Danjah I have not tried using the eclipse variable so sure whether it will work or not, not to forget we need the source folder in the `/assets` directory and not at the regular source location – dhaval Feb 21 '13 at 12:03
  • this solution is not compatible with source control or common sense -1 – jheriko Mar 14 '13 at 00:11
  • @jheriko you do realize that I answered this a year back!!! Also please suggest the solution you are using which matches the common sense and source control. I am using `git` and it works fine. – dhaval Mar 14 '13 at 06:08
  • it may work, but the idea is platform dependent and external to the files that are part of your project. keeping everything 'obvious' but not 'hiding' things in the filesystem is generally good practice and ensures compatibility across all source control you may encounter. git is great, but its very modern and little used commercially - cvs, p4, svn etc. are all nastier to varying degrees and in their own ways. the common sense i was referring to is perhaps not so common - just that data should be treated as such regardless as to its nature (i.e. be encoded obviously where suitable). – jheriko Jun 05 '13 at 00:58
2

Don't know how does it work in MacOS but I guess you can create a symbolic link with ln, putting your www folder inside Eclipse's assets. I do it both in Windows and Linux and work ok.

ciberado
  • 21
  • 1
  • Yes, thank you for this solution, it would definitely work on OSX. However, I should have mentioned that I am looking for a way to do this in Eclipse without filesystem-links, because anyone checking the project out of our svn would have to set the links up by hand. – sne11ius Jul 27 '11 at 14:52
  • Umh... something like this? http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-45.htm – ciberado Aug 01 '11 at 19:36
  • see also http://stackoverflow.com/questions/5648493/load-webview-with-html-file-linked-to-assets-folder – Paul Beusterien Jan 06 '12 at 17:19