Cordova: How to set Platform-specific config.xml file which is not overwritten after cordova build?

后端 未结 4 773
说谎
说谎 2021-02-08 14:30

I use Cordova with two platforms ios and android. When I change something in my

Project/config.xml 

it will be merged into

Pro         


        
4条回答
  •  执笔经年
    2021-02-08 15:22

    Since I have not yet found a better way, I suggest saving the config.xml files as you want them in some other location, and writing a script which does a cordova prepare, then copies the config.xml file to where it should go before compiling, and then have it run cordova compile. cordova buld just does a cordova prepare followed by a cordova compile, so a script that does this copying between these two steps is equivalent to a cordova build, but one which preserves your custom files.

    If you are using the xcode IDE, you can add a pre-action script to the iOS project's build:

    1. Select Product > Scheme > Edit Scheme
    2. Select Build > Pre-actions from the left
    3. Click + and select "New Run Script Action"

    And for the script you can enter:

    1. cordova prepare
    2. the cp commands to copy your saved config.xml and anything else you want to copy.
    3. anything else you'd like to do.

    After that, doing a build from inside xcode will refresh your common code files, preserve your edits to files, and do a build.

    This is clearly a workaround, but it does have the virtue that you can copy different versions of config.xml and of any other files into different platform directories.

    One caveat of this is that you must be careful whenever you do something with the Cordova tools which make changes to config.xml or any other file you are preserving through a prepare that you would want to keep. In particular, you must remember to update your custom config.xml file whenever you add or remove a plugin.

    I hope the Cordova tool developers either add support for this kind of reasonable desire, or improve the documentation if it actually is already supported, because this.

提交回复
热议问题