0

I want to replace something in AndroidManifest.xml using shell script. I use MPatcher tool to run .sh scripts on Android. My problem is that I can't replace those string:

    <uses-permission

        android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

With:

    <uses-permission

        android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- Игра станет хранить миры по старому пути благодаря методу Egornya. -->

    <uses-permission

        android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

I've tried a lot of things, nothing works. Either it issues an error, or it writes successfully replaced, but nothing has changed. Examples of codes:

sed -i '/<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" \/>/{

    i\

    <!-- Игра станет хранить миры по старому пути благодаря методу Egornya. -->\

    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />\

}' "$MANIFEST_PATH"

sed -i '/<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" \/>/ {

    s/.*/<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" \/>\

    <!-- Игра станет хранить миры по старому пути благодаря методу Egornya. -->\

    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" \/>/

}' "$MANIFEST_PATH"

sed -i '/<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" \/>/ { s/.*/<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" \/> <!-- Игра станет хранить миры по старому пути благодаря методу Egornya. --> <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" \/>/ }' "$MANIFEST_PATH"

so can someone give me a working code? I just can't do anything with it. Even ChatGPT can't help.

7
  • Please don’t post images of code, error messages, or other textual data. Commented Aug 1, 2024 at 5:54
  • Without a proper minimal reproducible example it's hard to point to a specific duplicate. Generally don't use traditional regex tools to edit structured formats like XML. Commented Aug 1, 2024 at 5:58
  • From the data you posted, the uses-permission tag comprises two lines in the XML file, but your sed command assumes that it is in a single line. BTW, I find your posting difficult to read -it's hard to see what is code and what is just your comment. Please fix your formatting. Commented Aug 1, 2024 at 13:39
  • @user1934428 comment was Fixed. Btw what should I use instead of "sed" then? Commented Aug 5, 2024 at 9:10
  • The duplicate already answers exactly that question. Commented Aug 5, 2024 at 12:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.