phonegap / phonegap-cli

PhoneGap and PhoneGap/Build command-line interface
Apache License 2.0
489 stars 157 forks source link

PhoneGap 3.6 and Icon Path Issues #522

Open Vasanthi-S opened 9 years ago

Vasanthi-S commented 9 years ago

With the PhoneGap 3.6.3 CLI release (http://phonegap.com/blog/2014/11/13/p...) it was stated that the config.xml file should be moved from the app's web directory to the root directory. But this is contradicting with the statement "Please ensure that your config.xml file is at the top level of your application (the same level as your index.html file). Otherwise it will not be loaded correctly." from: http://docs.build.phonegap.com/en_US/configuring_basics.md.html

It was also stated that icon and splash screens should be relative to the project root (makes sense, they would also be relative to the new location of the config.xml file). I'm presuming this means that you can also include icons from locations outside the www folder (this is from a snippet in the above post).

What we're noticing, is that for remote build, the icon paths must continue to be relative to the www folder. If not, they will be ignored. Furthermore, resources that exist outside the www folder will never be copied / uploaded to the build server at all.

For example: <gap:splash src="www/res/screen/android/screen-ldpi-portrait.png"/> does not work <gap:splash src="res/screen/android/screen-ldpi-portrait.png" /> works fine, irrespective of the location of my config.xml file (it could be in the project root or in the www folder) works fine.

Also, placing the config.xml file in the www folder as opposed to in the project root seems to still work (and would make more sense, given image path locations).

We tried the 4.2 CLI and the behavior is the same, even when specifying version 3.7 for the remote build in the config.xml file.

Can you please clarify a) Where should the config.xml file be placed for version 3.6 or higher? b) Should the image paths be relative to www or the project root? (empirically, it looks like the former) c) Can we place resources outside the www folder?

wildabeast commented 9 years ago

Confirmed this is a bug, introduced when cordova moved the config.xml from the www/ to the project root. Icon paths then had to be relative the project root (i.e. www/res/...). When remote builds occur, the config.xml is copied to the www before zipping and sending off ... and while build expects icon paths in the config.xml to be relative to the www/, they will still be relative to the directory above.

If you're only doing remote builds, then you can just keep your config.xml and icons in your www/, and paths should be relative to the www/.

If you're trying to support both local builds and remote builds, to work around this now, one solution might be to use a structure like this:

my-proj/
  |- www/
  |- res/
      |- icons/

And then use hooks or a script to copy your res/ directory before doing a remote build:

# in my-proj/
cp res www
phonegap remote build ios
# remove for local builds
rm -rf www/res/ 

This way the icon paths (i.e. res/icons/whatever.png) will resolve both relative to the root (for local builds) and relative to the www (for remote builds).

As for permanently fixing this -- we'll need to discuss. There's currently a disconnect between PGB and the CLI on what the root directory is.

mwbrooks commented 9 years ago

Thanks for summarizing this @wildabeast!

brianvfernandes commented 9 years ago

@wildabeast, I appreciate the detailed analysis and workarounds.

We're running into this problem with MyEclipse 2015 where our more recent releases ship with PG 3.6.3 and use the same CLI for our PG build tooling. As per instructions in the release blog, for new projects created with 3.6.3, we moved the config.xml into the project root and corrected the paths within as well. Unfortunately, we were remiss in not fully testing the remotely built binaries or we'd have found this problem a lot sooner. We already use hook scripts for local builds, so they worked fine.

The workaround we have posted for our users is the same as your first suggestion - move config.xml into www and correct the paths accordingly; it has been working fine. Our hook scripts seem to be intelligent enough to "do the right thing" for local builds, irrespective of the location of the config.xml file (it assumes that relative paths in config.xml are based on the location of the config.xml file).

I must say more users are running into this problem, but other than pointing them to a workaround, we can't put a fix into MyEclipse because it does depend on how this issue is fixed by PhoneGap build - I'm trying to avoid putting a temporary fix which we may be forced to withdraw when the issue is remotely fixed.

My thoughts: 1) If relative paths are being specified in a file (like the config.xml file), those paths should be considered relative to the location of that file and not relative to fixed folders like project root or www. I'm unsure how this works in Cordova, though.

2) I realize that because the config.xml file is being moved into www (if not already there) before it is uploaded, the build service doesn't really know whether the config.xml file was originally in www or whether it was moved into that location. Nevertheless, could it assume that for a 3.6 or higher project, the config.xml file was in the project root and all paths within are therefore relative to project root? That's where the create command places the config.xml file anyway. This way, 3.6 builds will work as advertised with no changes required in the user's projects.

Thanks again for taking a look!

kcivey commented 9 years ago

Thanks, @wildabeast! I've been trying to find an explanation of that for days.

You mention hooks, but is there actually a way to run a hook when doing a remote build? Aren't hooks a purely cordova-cli thing and thus not used for "remote" commands?

brianvfernandes commented 9 years ago

@wildabeast / @mwbrooks has there been any progress on a fix for this issue? We have a release of MyEclipse coming up and I'd like to make the right, permanent fix in our tooling. Thanks!

eb1 commented 9 years ago

Stumbled onto this issue after asking around on Stack Overflow.

I'd also love to see a more permanent fix for this issue, so that PG build and the CLI can use the same config.xml / icon and splash screen set.

mwbrooks commented 8 years ago

Moving this into the Backlog and labelling PGB.

examinedliving commented 7 years ago

Is this really still open? Coupled with the fact that every service that uses Cordova, .e.g. Intel XDK, Monaca has a different was of laying out the path structure, this becomes painfully complicated. Is it really that difficult to fix this? I'm not being belligerent - I'm really asking. It seems so weird that this isn't resolved a year later.

marcomilone commented 7 years ago

The problem is that copying res into www increase the final app package size. That's why I'll really prefere that: / /www /res /config.xml

Phonegap should support packages with that folder structure and search for www near config.xml Should I name the root folder "app" to make it standard (zip / unzip story)? No problem.

filmaj commented 7 years ago

@kcivey I believe support for executing hooks on remote commands is filed in #44 - can track support for that feature in that issue.

It sounds like this is an issue with the cli itself, in that it moves files around in this weird way to support PhoneGap Build. However, I believe PGB now supports the config.xml being outside of the www. So this points to this being an issue within the CLI itself. I will take a closer look.