Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode Build not updating JS and HTML

I am using XCode 5.0.2 and Cordova 3.4.0-0.1.3 - What I find is after creating the project using the Cordova CLI and opening in XCode, no changes to the index.html file and index.js file are ever carried over to the simulator when I click run. I have to open terminal and issues a Cordova Build command and then run the simulator and it works

I followed all the instructions here:

Phonegap - developing and launching app on simulator

xcode 4 + phonegap ... not update JS upon build?

And none of it works! any one a have a solution to this, because having to switch back and forth is becoming a pain.

like image 617
Ksliman Avatar asked Mar 06 '14 17:03

Ksliman


3 Answers

You can add a pre-action script to your XCode project's build. To do this:

  1. Select Product > Scheme > Edit Scheme from the menu (or ⌘ < on keyboard)
  2. Select Build > Pre-actions from the left
  3. Click + and select "New Run Script Action"
  4. Add a script like this:

    cd /path/to/your/cordova/project/
    cordova prepare ios > xcode-prepare-results.txt
    

Now XCode should always run cordova prepare before building your project so you don't have to jump to terminal. You can see the output of prepare in the file xcode-prepare-results.txt.

Note, that depending on how your cordova executable is set up and which shell you use, you might have to either change the shell or modify your PATH in order for the script to find cordova.

like image 73
ville Avatar answered Oct 09 '22 01:10

ville


So after much searching I seem to have found a solution that works, here is what I did. After looking at other Stackoverflow questions I found someone that said this worked for them.

Find the file called copy-www-build-step.sh.

Mine was in [project_folder]/platforms/ios/cordova/lib/copy-www-build-step.sh

In that file, find the lines beginning rsync -a "...

Add -c to the rsync lines, so they ready rsync -a -c "...

Well I tried that and it did not work on its own. I also tried the answer from Ville and that pulled closer but no cigar. Finally I took what the command from Ville and put it in the copy-www-build-step.sh file

so my top line is now

cd /path/to/your/cordova/project/
cordova prepare

SRC_DIR="www/"
DST_DIR="$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME/www"
COPY_HIDDEN=
ORIG_IFS=$IFS
IFS=$(echo -en "\n\b")
.....
.....
.....etc etc 

And now I make change , and click run , bam all is updated. I hope this helps someone else.

like image 35
Ksliman Avatar answered Oct 09 '22 02:10

Ksliman


Other answers in this thread either didn't work for me or screwed up cordova plugins e.g. InAppBrowser, so i finally came up with this:

Edit the file copy-www-build-step.sh and add the following row in the beginning:

cp -fR ../../www/ www/

so it should look like:

...
cp -fR ../../www/ www/ # new code

SRC_DIR="www/"
...

This way your code will be updated properly and your plugins will work

like image 34
Yossi Shasho Avatar answered Oct 09 '22 03:10

Yossi Shasho