- Download AXMLPrinter2.jar
- Build your solution and create an archive (.apk) by selecting Build->Archive...
- After archiving is done, open folder and find the archived *.apk, open the archive (for example using 7Zip) and extract/unzip
AndroidManifest.xml - Open any text editor and type:
start cmd.exe /c "java -jar AXMLPrinter2.jar AndroidManifest.xml > AndroidManifest.plaintext.xml"and save it as a*.batfile in the same directory - Run the
*.batfile and check the resultingAndroidManifest.plaintext.xmlfile. This is the file we will be editing using a shell script - Create the shell script you need. It should target
obj\$configuration\android\AndroidManifest.xmlfor example:(Get-Content 'obj\Release\*\android\AndroidManifest.xml').replace('<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />', '') | Set-Content 'obj\Release\*\android\AndroidManifest.xml'theRemoveAndroidPermission.ps1script above findsREAD_EXTERNAL_STORAGEpermission and removes them - Save your scrip into your solution directory
- Open your project file
*.csprojin any text editor. Scroll to the bottom, and a new custom tag to execute your script:<Target Name="BeforeCreateBaseApk" BeforeTargets="_CreateBaseApk"> <Exec Command="powershell -noexit "& '$(SolutionDir)[YOUR SCRIPT NAME].ps1'" /> </Target> In my case for exaple: <Target Name="BeforeCreateBaseApk" BeforeTargets="_CreateBaseApk" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <Exec Command="powershell -noexit "& '$(SolutionDir)RemoveAndroidPermissions.ps1'" /> </Target>
- Save the changes to
*.csprojand try rebuilding your solution. If it fails, you either did something wrong or your script corupts theAndroidManifest.xml - After building succeeds, see that the changes to
obj\$configuration\android\AndroidManifest.xmlwere made successfully - Repeate steps 2-5, in other words make and archive, extract
AndroidManifest.xml, useAXMLPrinter2.jarand see that the changes were successful - You are done! ;)
Last active
January 21, 2025 14:03
-
-
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
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.