run-as: Could not set capabilities: Operation not permitted

AndroidAdb

Android Problem Overview


on android 6.0.1 I am getting this error when trying to use run-as.

⋊> ~ adb shell                                                          14:29:01
shell@trlte:/ $ run-as org.ligi.passandroid                                    
run-as: Could not set capabilities: Operation not permitted

I really like the run-as command - is there a way to get it to work on 6.0.1 ?

Android Solutions


Solution 1 - Android

If you have a SAMSUNG device, don't bother - SAMSUNG broke run-as by dropping the setuid flag (so run-as has no chance of switching to a different identity).

Also don't bother trying the Smart Switch "reinitialize device" workaround, it won't work until SAMSUNG fixes it in the firmware (so it is worth updating to the latest version).

Use some other method to access your app's data, like adb backup:

adb backup -f data.ab <my.package>
dd if=data.ab  bs=24 skip=1 | openssl zlib -d > data.tar

Instead of dd you can use the abe tool, which can also write .ab files.

Solution 2 - Android

For me, it went like this. I am using Samsung s6 API 24. The error list log's detail was the same as mentioned in the question. But when I checked the Build Logs I found the solution written there. To set the MSBuild. So I followed the following steps to resolve this and the app ran successfully. To correct this problem I had to

Unload Android Project from solution explorer Right-Click unloaded project and "Edit Project File" Searched code for "EmbedAssembliesIntoApk" Found the occurrence in the project file

<EmbedAssembliesIntoApk>false</EmbedAssembliesIntoApk>

Change it to true and reload the project.

<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>

Ran the app and the app starts running on Samsung s6

Solution 3 - Android

The solution for me was the parameter -autolaunch in the Debugger configuration of the project in the field Parameters.

I use Delphi 10.2 with S7 Edge Android 7

Solution 4 - Android

Unlike another answer here, I have also tried to use smart switch & hard device resetting, but unfortunately that approach did not work for me (Wasted extra one hour just to try out that approach). Besides not working, it might create additional problem "samsung account: session expired" - problem, which can be fixed only if you have root access to your device.

I by myself have used instructions from here: https://www.youtube.com/watch?v=Sy4FWLHxGYs

and then from here: https://www.tomsguide.com/us/samsung-galaxy-s6-guide,review-2856-3.html

for getting root access to your device, and after that run-as can be executed with additional command "su -c" as for get root user. So whole command will look like this:

su -c run-as org.ligi.passandroid

WARNING: Gaining root access to your device will most probably void your device warranty if you have any left.

Additionally to this, I wanted to be able to debug my application inside Samsung Galaxy S6, so I've altered Visual studio components, more instructions can be found here:

https://issuetracker.google.com/issues/37093233#comment53

If you happen to have Samsung based android device - I have already reported that bug to Samsung, but I've could not get any time schedule if when and if at all they are going to fix this issue. If you own some other Android device - makes sense to report this problem to manufacturer.

Solution 5 - Android

I was working from Delphi 10.1 berlin. I was presented with the same problem and my solution was to configure the sdk to the previous version. I was using Android SDK 25.2.5.32bit and downgraded to android SDK 24.3.3 32 bit. To configure:

> Tools->Environment Options -> SDK Manager

Then, add the necessary sdk, in this case android SDK 24.3.3 32 bit.

Solution 6 - Android

@RustyX answer helped my partially. zlib didn't work in my Mac. So I had to use the Android Backup Extractor to convert .ab file to .tar file. You can download it here.

For the full step by step instruction, refer here.

Solution 7 - Android

In Visual Studio, App properties, Android Options, changing the debugger from C++ to .Net(Xamarin) seems to have fixed the problem for a mixed C++/C# app.

Solution 8 - Android

Also got this error today when I tried to deploy/debug my application on a Samsung Xcover 3 running Android 6. I solved it by changing the project property "Android Options / Use Fast Deployment" to false.

Solution 9 - Android

Here is solution for MS Visual Studio 2022.

https://www.youtube.com/watch?v=_r9GLm0k55o

enter image description here

Just uncheck the "Use Fast Deployment".

Solution 10 - Android

I had previously posted an answer here which was deleted, maybe because it was a link to another stackoverflow question referring to the answer I gave there, instead of containing the full answer.

Reposting its contents here from https://stackoverflow.com/a/43242739/7823460:

I had a very similar issue on Samsung Galaxy S6 Edge, trying to start debugging on VS2015, I got a different error, much less verbose than in the attached screenshot:

run-as: Could not set capabilities: Operation not permitted

Based on the contents of the attached screenshot above, I tried 'initializing' / factory resetting the device using Samsung's Smart Switch and it actually fixed the 'run-as' issue I was having.

This is the only solution which worked and didn't involve rooting the device, so I believe it must be publicly available. Of course people attempting this should keep in mind that factory reset means that data will be lost, unless it's backed up. The same Samsung software helps with backing up your data.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionligiView Question on Stackoverflow
Solution 1 - AndroidrustyxView Answer on Stackoverflow
Solution 2 - AndroidSaadurRehmanView Answer on Stackoverflow
Solution 3 - AndroidHelge LangeView Answer on Stackoverflow
Solution 4 - AndroidTarmoPikaroView Answer on Stackoverflow
Solution 5 - AndroidJhon Janer Ramirez FlorezView Answer on Stackoverflow
Solution 6 - AndroidHenryView Answer on Stackoverflow
Solution 7 - Androiduser1725145View Answer on Stackoverflow
Solution 8 - Androiduser2667767View Answer on Stackoverflow
Solution 9 - AndroidNoWarView Answer on Stackoverflow
Solution 10 - AndroidGiedriusView Answer on Stackoverflow