Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Guiorgy/75e9f9a0acb47fba96bc4eea537f0143 to your computer and use it in GitHub Desktop.
Save Guiorgy/75e9f9a0acb47fba96bc4eea537f0143 to your computer and use it in GitHub Desktop.
Currently (11/1/19) Xamarin does not support merging manifest, or having different manifests for different build configurations. This is a workaround originally found by AlexanderMelchers at https://forums.xamarin.com/discussion/97461/android-manifest-file-merge-rules
  1. Download AXMLPrinter2.jar from https://code.google.com/archive/p/android4me/downloads
  2. Build your solution and create an archive (.apk) by selecting Build->Archive...
  3. After archiving is done, open folder and find the archived *.apk, open the archive (for example using 7Zip) and extract/unzip AndroidManifest.xml
  4. Open any text editor and type: start cmd.exe /c "java -jar AXMLPrinter2.jar AndroidManifest.xml > AndroidManifest.plaintext.xml" and save it as a *.bat file in the same directory
  5. Run the *.bat file and check the resulting AndroidManifest.plaintext.xml file. This is the file we will be editing using a shell script
  6. Create the shell script you need. It should target obj$configuration\android\AndroidManifest.xml for example: (Get-Content 'obj\Release*\android\AndroidManifest.xml').replace('', '') | Set-Content 'obj\Release*\android\AndroidManifest.xml' the RemoveAndroidPermission.ps1 script above finds READ_EXTERNAL_STORAGE permission and removes it
  7. Save your scrip into your solution directory
  8. Open your project file *.csproj in any text editor. Scroll to the bottom, and a new custom tag to execute your script: In my case for exaple:
  9. Save the changes to *.csproj and try rebuilding your solution. If it fails, you either did something wrong or your script corupts the AndroidManifest.xml
  10. After building succeeds, see that the changes to obj$configuration\android\AndroidManifest.xml were made successfully
  11. Repeate steps 2-5, in other words make and archive, extract AndroidManifest.xml, use AXMLPrinter2 and see that the changes were successful
  12. You are done! ;)
@Guiorgy
Copy link
Author

Guiorgy commented Jan 15, 2019

In my case, for example, I had several build configurations, some of which required READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions, but others did not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment