当cordova构建时,我有更改配置的任务。我必须在两个部分中更改APP_SECRET的值。一个用于android应用程序,一个用于ios应用程序。这些案例在azure devops管道中使用,当项目构建XML时,这些参数必须更改:
<?xml version='1.0' encoding='utf-8'?>
<widget android-versionCode="14" id="com.someaapp.com" ios-CFBundleVersion="0" version="2.0.5" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>testApp</name>
<description>
Test App
</description>
<author email="" href="">
</author>
<content src="index.html" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<preference name="LoadUrlTimeoutValue" value="80000" />
<platform name="android">
<preference name="APP_SECRET" value="7bae78da-eeb7-4r7d-a7bf-c6r3ffdg03fc" />
<allow-intent href="market:*" />
<preference name="StatusBarOverlaysWebView" value="false" />
<preference name="StatusBarBackgroundColor" value="#000000" />
<icon density="ldpi" src="res/icons/android/ldpi.png" />
<icon density="mdpi" src="res/icons/android/mdpi.png" />
<icon density="hdpi" src="res/icons/android/hdpi.png" />
<icon density="xhdpi" src="res/icons/android/xhdpi.png" />
<icon density="xxhdpi" src="res/icons/android/xxhdpi.png" />
<icon density="xxxhdpi" src="res/icons/android/xxxhdpi.png" />
<splash density="port-ldpi" src="res/screens/android/splash-port-ldpi.png" />
<splash density="port-mdpi" src="res/screens/android/splash-port-mdpi.png" />
<splash density="port-hdpi" src="res/screens/android/splash-port-hdpi.png" />
<splash density="port-xhdpi" src="res/screens/android/splash-port-xhdpi.png" />
<splash density="port-xxhdpi" src="res/screens/android/splash-port-xxhdpi.png" />
<splash density="port-xxxhdpi" src="res/screens/android/splash-port-xxxhdpi.png" />
</platform>
<platform name="ios">
<preference name="APP_SECRET" value="fffdffdge16-39ee-485b-bsdfd-4aecf25c5891" />
<config-file parent="NSAppTransportSecurity" platform="ios" target="*-Info.plist">
<dict>
<key>NSAllowsArbitraryLoads</key>
<false />
</dict>
</config-file>
<icon height="1024" src="res/icons/ios/icon-1024.png" width="1024" />
<icon height="29" src="res/icons/ios/icon-small.png" width="29" />
<icon height="58" src="res/icons/ios/icon-small@2x.png" width="58" />
<icon height="87" src="res/icons/ios/icon-small@3x.png" width="87" />
<icon height="40" src="res/icons/ios/icon-small-40.png" width="40" />
<icon height="80" src="res/icons/ios/icon-small-40@2x.png" width="80" />
<icon height="120" src="res/icons/ios/icon-small-40@3x.png" width="120" />
<icon height="50" src="res/icons/ios/icon-small-50.png" width="50" />
<icon height="100" src="res/icons/ios/icon-small-50@2x.png" width="100" />
<icon height="57" src="res/icons/ios/icon.png" width="57" />
<icon height="114" src="res/icons/ios/icon@2x.png" width="114" />
<icon height="60" src="res/icons/ios/icon-60.png" width="60" />
<icon height="120" src="res/icons/ios/icon-60@2x.png" width="120" />
<icon height="180" src="res/icons/ios/icon-60@3x.png" width="180" />
<icon height="72" src="res/icons/ios/icon-72.png" width="72" />
<icon height="144" src="res/icons/ios/icon-72@2x.png" width="144" />
<icon height="76" src="res/icons/ios/icon-76.png" width="76" />
<icon height="152" src="res/icons/ios/icon-76@2x.png" width="152" />
<icon height="167" src="res/icons/ios/icon-167.png" width="167" />
<icon height="167" src="res/icons/ios/icon-83.5@2x.png" width="167" />
<splash height="480" src="res/screens/ios/Default~iphone.png" width="320" />
<splash height="960" src="res/screens/ios/Default@2x~iphone.png" width="640" />
<splash height="1024" src="res/screens/ios/Default-Portrait~ipad.png" width="768" />
<splash height="2048" src="res/screens/ios/Default-Portrait@2x~ipad.png" width="1536" />
<splash height="1136" src="res/screens/ios/Default-568h@2x~iphone.png" width="640" />
<splash height="1334" src="res/screens/ios/Default-667h.png" width="750" />
<splash height="2208" src="res/screens/ios/Default-736h.png" width="1242" />
<splash height="2436" src="res/screens/ios/Default-x.png" width="1125" />
<splash height="1792" src="res/screens/ios/Default-xr.png" width="828" />
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<preference name="DisallowOverscroll" value="true" />
<preference name="webviewbounce" value="false" />
<preference name="StatusBarOverlaysWebView" value="false" />
<preference name="StatusBarBackgroundColor" value="#000000" />
</platform>
<preference name="ShowSplashScreenSpinner" value="false" />
<preference name="Orientation" value="portrait" />
<feature name="UniversalAnalytics">
<param name="ios-package" value="UniversalAnalyticsPlugin" />
</feature>
<engine name="android" spec="^8.0.0" />
<engine name="ios" spec="5.0.1" />
<plugin name="cordova-plugin-device" spec="^2.0.2" />
<plugin name="cordova-plugin-exitapp-ios" spec="0.0.2" />
<plugin name="cordova-plugin-statusbar" spec="^2.4.2" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
<plugin name="cordova-plugin-network-information" spec="^2.0.1" />
<plugin name="phonegap-plugin-mobile-accessibility" spec="^1.0.5" />
<plugin name="cordova-plugin-inappbrowser" spec="^2.0.2" />
<plugin name="cordova-plugin-msal" spec="file:cordova-plugins\cordova-plugin-msal">
<variable name="MSAL_APP_ID_INPUT" value="BLANK" />
</plugin>
<plugin name="cordova-plugin-app-version" spec="^0.1.9" />
<plugin name="cordova-custom-config" spec="5.1.0" />
<plugin name="cordova-plugin-splashscreen-iphonex-support" spec="^1.0.1" />
<plugin name="cordova-plugin-appcenter-analytics" spec="^0.5.1" />
<plugin name="cordova-plugin-appcenter-crashes" spec="^0.5.1" />
</widget>
我使用这些代码来更改值:
$filePathToTask = "D:\Downloads\config.xml"
[xml]$config = Get-Content $filePathToTask
$value = Read-Host -Prompt 'Enter new APP_SECRET: '
$node = $config.widget.platform.preference
$node.SetAttribute("value", "$value");
$config.Save($filePathToTask)
但它挑战所有的值在xml,我如何做才能改变APP_SECRET的值在安卓和ios部分,他们必须是不同的
发布于 2019-11-27 21:15:51
您需要更多地指定节点,以便仅更改名为'APP_SECRET‘的节点的值。
另外,我建议用新的名称保存更新后的配置文件,这样(至少在测试时)就不会覆盖原来的配置文件。
$configIn = 'D:\Downloads\config.xml'
$configOut = 'D:\Downloads\config2.xml'
[xml]$config = Get-Content $configIn -Raw
$secret = Read-Host -Prompt 'Enter new APP_SECRET: '
$config.widget.platform.preference |
Where-Object { $_.Name -eq 'APP_SECRET' } |
ForEach-Object {
$_.SetAttribute("value", $secret)
}
$config.Save($configOut)
希望这能有所帮助
https://stackoverflow.com/questions/59070862
复制相似问题