XCode Build 不更新 JS 和 HTML
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22231767/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XCode Build not updating JS and HTML
提问by Ksliman
I am using XCode 5.0.2and Cordova 3.4.0-0.1.3- What I find is after creating the project using the Cordova CLIand opening in XCode, no changes to the index.htmlfile and index.jsfile are ever carried over to the simulator when I click run. I have to open terminal and issues a CordovaBuild command and then run the simulator and it works
我正在使用XCode 5.0.2和Cordova 3.4.0-0.1.3- 我发现在使用Cordova CLI创建项目并在XCode 中打开后,没有对index.html文件和index.js文件进行任何更改当我单击运行时转到模拟器。我必须打开终端并发出CordovaBuild 命令,然后运行模拟器并且它可以工作
I followed all the instructions here:
我按照这里的所有说明进行操作:
Phonegap - developing and launching app on simulator
xcode 4 + phonegap ... not update JS upon build?
xcode 4 + phonegap ...在构建时不更新 JS?
And none of it works! any one a have a solution to this, because having to switch back and forth is becoming a pain.
而且都没有效果!任何人都有解决方案,因为不得不来回切换变得很痛苦。
采纳答案by Ksliman
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.
因此,经过大量搜索后,我似乎找到了一个有效的解决方案,这就是我所做的。在查看了其他 Stackoverflow 问题后,我发现有人说这对他们有用。
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 "...
找到名为 copy-www-build-step.sh 的文件。
我的在 [project_folder]/platforms/ios/cordova/lib/copy-www-build-step.sh
在该文件中,找到以 rsync -a "...
将 -c 添加到 rsync 行,以便它们准备好 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
好吧,我试过了,但它本身不起作用。我还尝试了 Ville 的答案,结果拉近了,但没有雪茄。最后,我从 Ville 获取了命令并将其放入 copy-www-build-step.sh 文件中
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.
现在我进行更改,然后单击运行,全部更新。我希望这对其他人有帮助。
回答by ville
You can add a pre-action script to your XCode project's build. To do this:
您可以向 XCode 项目的构建中添加预操作脚本。去做这个:
- Select Product > Scheme > Edit Scheme from the menu (or ? < on keyboard)
- Select Build > Pre-actions from the left
- Click + and select "New Run Script Action"
Add a script like this:
cd /path/to/your/cordova/project/ cordova prepare ios > xcode-prepare-results.txt
- 从菜单中选择产品 > 方案 > 编辑方案(或键盘上的 ? <)
- 从左侧选择 Build > Pre-actions
- 单击 + 并选择“新建运行脚本操作”
添加这样的脚本:
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.
现在,在构建项目之前,XCode 应该始终运行 cordova prepare,这样您就不必跳转到终端。您可以在文件 xcode-prepare-results.txt 中看到 prepare 的输出。
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.
请注意,根据您的cordova 可执行文件的设置方式以及您使用的shell,您可能必须更改shell 或修改PATH 以便脚本找到cordova。
回答by Yossi Shasho
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:
该线程中的其他答案要么对我不起作用,要么搞砸了 Cordova 插件,例如 InAppBrowser,所以我终于想出了这个:
Edit the file copy-www-build-step.shand add the following row in the beginning:
编辑文件copy-www-build-step.sh并在开头添加以下行:
cp -fR ../../www/ www/
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 andyour plugins will work
这样您的代码将正确更新并且您的插件将正常工作
回答by CodeWeenie
To have the source files automatically copied from the www source directory to the platforms/ios/www directory when you click the Run button in XCode:
当您在 XCode 中单击“运行”按钮时,要将源文件自动从 www 源目录复制到platforms/ios/www 目录:
In XCode, choose Product->Scheme->Edit Scheme...
Expand the triangle for Build->Pre-actions
Click the "+" to create a new Pre-action
在 XCode 中,选择 Product->Scheme->Edit Scheme...
展开三角形Build-> Pre-actions
点击“+”创建一个新的 Pre-action
You can leave the "Shell" setting blank.
Set "Provide build settings from" to the project you are building. This is important.
您可以将“外壳”设置留空。
将“提供构建设置来自”设置为您正在构建的项目。这个很重要。
In the script area enter:
在脚本区输入:
cd ${PROJECT_DIR}/../..
echo "--- Start ---" > xcode-prepare-ios-results.txt
echo "Running cordova prepare ios command..."
pwd >> xcode-prepare-ios-results.txt
cordova prepare ios --verbose >> xcode-prepare-ios-results.txt
echo "--- Finished ---" >> xcode-prepare-ios-results.txt
This works for me with XCode 8.2 and Apache Cordova 6.x
这适用于 XCode 8.2 和 Apache Cordova 6.x
回答by Ryan Ore
I also edited the copy-www-build-step.shfile, however you don't want to use an absolute path from your User folder. If you are working with other developers you would have to change that every time you check out code.
我还编辑了copy-www-build-step.sh文件,但是您不想使用用户文件夹中的绝对路径。如果您正在与其他开发人员一起工作,则每次检查代码时都必须进行更改。
It's not a big deal, just change:
这没什么大不了的,只是改变:
SRC_DIR="www/"
To:
到:
SRC_DIR="../../www/"
UPDATEWorked for me on Cordova and Phonegap.
更新在 Cordova 和 Phonegap 上对我来说有效。
回答by Sbat
Run "cordova prepare ios
" during the building phases:
cordova prepare ios
在构建阶段运行“ ”:
- Open Xcode.
- Select your project.
- Go to "Build Phases".
- Go on "+" to add a "New Run Script Phase".
- Move this section before "Copy www directory".
- Add the following lines (for Mac):
cd /Users/*/YOUR_PROJECT_FOLDER
(Change your project folder)/Users/*/.nvm/versions/node/v?.?.?/bin/node node_modules/cordova/bin/cordova prepare ios
(Change the path to node version)
- 打开 Xcode。
- 选择您的项目。
- 转到“构建阶段”。
- 继续“+”以添加“新运行脚本阶段”。
- 将此部分移到“复制 www 目录”之前。
- 添加以下几行(对于 Mac):
cd /Users/*/YOUR_PROJECT_FOLDER
(更改您的项目文件夹)/Users/*/.nvm/versions/node/v?.?.?/bin/node node_modules/cordova/bin/cordova prepare ios
(更改节点版本的路径)
After "Play" the www-folder will automatically refresh!
“播放”后,www 文件夹将自动刷新!
回答by Karman De Lange
@Ksliman I modified you code a bit to work on my system and make slight bit more generic.
@Ksliman 我修改了你的代码以在我的系统上工作并使其更通用。
top of file copy-www-build-step.sh
文件顶部 copy-www-build-step.sh
## New Code Begin ###
cd ../../
PATH=${PATH}:/usr/local/bin
cordova prepare ios
## New Code End ###
SRC_DIR="www/"
回答by armnov
simply type:
只需键入:
cordova prepare
on your terminal and run your project again in Xcode
在您的终端上并在 Xcode 中再次运行您的项目
回答by Alex Harper
Simple solutions is to build the app with cordova using:
简单的解决方案是使用cordova构建应用程序:
sudo cordova build ios
Then go to xcode > Product > Clean
然后转到 xcode > 产品 > 清洁
Then go to xcode > Run (Play Button)
然后转到 xcode > 运行(播放按钮)
回答by Mohammad Nurdin
I suggest you clean before build your xcode project. And one more thing, make sure you build again your project using cordova build, not inside xcode because it's totally different.
我建议您在构建 xcode 项目之前进行清理。还有一件事,请确保您使用cordova build 重新构建您的项目,而不是在xcode 中,因为它完全不同。
cordova build yourproject