Remove Phonegap generated permissions from apk file

  • 1
  • Question
  • Updated 4 years ago
  • Answered
Phonegap generates a lot of permissions when it creates the apk file.

How can I open and edit my apk file to remove the permissions?
Photo of Oscar

Oscar

  • 17 Posts
  • 0 Reply Likes

Posted 6 years ago

  • 1
Photo of John Weidner

John Weidner, Champion

  • 435 Posts
  • 80 Reply Likes
If you add the following to your config.xml your apk won't require all those permissions.

<preference name="permissions" value="none"/>

Any plugins you use will cause additional permissions to be added based on what the plugin can do. However, sometimes you might include a plugin but not use all of its features. For example, if you add the Media plugin but only use it for playing sounds it will add permissions for using video and accessing your SD card that you don't need. In this case, you may want to edit the .apk file like you asked. There is a tool called apktool that will help you. I use the following commands to remove some permissions and then rebuild the .apk file.



java -jar apktool.jar decode -f MyApp-release.apk

edit the manifest xml file and then package it back up using


java -jar apktool.jar build MyApp-release MyApp-release.apk

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore c:\users\john\my.keystore MyApp-release.apk johnweidner

c:\utils\sdk\build-tools9.1.0\zipalign -f -v 4 MyApp-release.apk MyApp-release2.apk
Photo of John Weidner

John Weidner, Champion

  • 435 Posts
  • 80 Reply Likes
Not that I know of. I think you currently do it manually by

1. use the apktool to extract the manifest file,
2. edit the manifest file and delete the lines you don't want
3. repackage the apk file with apktool
4. resign the file with jarsigner
5. zipalign the file

I'm sure someone couple write a script to put all of this together. Maybe someday Phone Gap Build will have an option that let's you use a plugin without having to inherit all of the plugins required permissions.
Photo of Oscar

Oscar

  • 17 Posts
  • 0 Reply Likes
I found this site http://www.decompileandroid.com/ which decompiles the apk file for you.. I was able to remove the permissions.
Now I need to convert it back to apk again.Any ideas how to do this?
Photo of John Weidner

John Weidner, Champion

  • 435 Posts
  • 80 Reply Likes
Use apktool to repackage, then jarsigner to resign it, and finally zipalign.
Photo of Oscar

Oscar

  • 17 Posts
  • 0 Reply Likes
Oh by the way. I made an configxml file with Configap and removed some permission + added . It works great now! No need to use command promt.
Photo of apkpure

apkpure

  • 1 Post
  • 0 Reply Likes
Thanks .
More tool here : apktool
Photo of Amir

Amir

  • 8261 Posts
  • 263 Reply Likes
Hi Oscar

Did the above answer by John provide any good helps? Let us know.

Thanks
Photo of Oscar

Oscar

  • 17 Posts
  • 0 Reply Likes
Hey,

It was the answer I was looking for but I was still not able to solve my problem.

Have you at Phonegap considered of making permissions alternatives in the settings menu?
Photo of Amir

Amir

  • 8261 Posts
  • 263 Reply Likes
Hi Oscar

That should be a great area to improvise. Hence, appreciate if you can create feature request at the following issue tracker:
https://github.com/phonegap/build/issues

Cheers!
Photo of John Weidner

John Weidner, Champion

  • 435 Posts
  • 80 Reply Likes
Photo of John Weidner

John Weidner, Champion

  • 435 Posts
  • 80 Reply Likes
You can now remove permissions without doing all this. You can just add some code to your config.xml. http://community.phonegap.com/nitobi/...