LoginSignup
0
0

More than 3 years have passed since last update.

BitirseでAndroidのXMLを書き換えたい

Last updated at Posted at 2019-07-19

概要

AndroidプロジェクトのXMLの設定ファイルをBitriseで書き換える方法
xmlstarletというツールで実現できました

インストール

Bitrise上

sudo apt install -y xmlstarlet

AndroidならUbuntuがdefaultだと思います。

Mac上で試す場合

brew install xmlstarlet

使い方

xmlstarlet edit --inplace -u "XML Path" --value "VALUE" "XML file path"

実際のコード一例

WorkflowのScriptステップで以下のコードを実行

xmlstarlet edit --inplace -u "/resources/string[@name='target_key']" --value "new value" Project/src/stage1/res/values/setting.xml

留意点

XMLファイルが正規化されるので以下のdiffが発生します。

  • インデントがスペース4個から2個に変更される
  • 改行が削除される

検証

スペースと改行を無視してdiffを出力する以下のコードを入れるとログで差分が見易いです。

git diff --ignore-all-space --ignore-blank-lines

リファレンス

xmlstarletドキュメント
http://xmlstar.sourceforge.net/doc/UG/xmlstarlet-ug.html#idm47077139594320

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0