60

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 ?

ligi
  • 39,001
  • 44
  • 144
  • 244
  • 4
    According to this, this is a bug on Samsung devices: https://code.google.com/p/android/issues/detail?id=206581#c4 – ChristophK May 25 '16 at 09:23

10 Answers10

81

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.

rustyx
  • 80,671
  • 25
  • 200
  • 267
  • 2
    Thanks, you are a life saver. But `zlib` didn't work on my Mac, so I had to use the `abe.jar` for extraction. See my answer https://stackoverflow.com/a/48077004/4747587 – Henry Jan 03 '18 at 12:07
  • 5
    @Henry As pointed [here](https://stackoverflow.com/questions/29830981/error-zlib-is-an-invalid-command) on mac you can do the following command : `dd if=data.ab bs=24 skip=1 | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" > data.tar` – Marc_Alx Mar 08 '18 at 13:30
  • This worked for me. Since I'm using Windows, I had to install Cygwin and copy your commands into a .sh and run the .sh. And it worked flawlessly. Thanks. – Martin Apr 25 '18 at 19:33
  • i am getting dd is not recognized as internal or external command – Vishal Thakkar Jul 27 '18 at 09:53
  • Based on this comment, after I uninstalled my application from Samsung device, Visual Studio failed to reinstall and debug, so I ran `adb uninstall com.companyname.packagename`. Now I am able to debug again. – Ranvir Jul 25 '21 at 02:22
12

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

SaadurRehman
  • 622
  • 8
  • 20
3

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

Helge Lange
  • 31
  • 1
  • 1
1

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.

TarmoPikaro
  • 4,723
  • 2
  • 50
  • 62
1

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.

Daniel
  • 14,004
  • 16
  • 96
  • 156
  • 1
    Welcome to Stack Overflow. Please write your answer in English, as Stack Overflow is an [English only site](https://meta.stackoverflow.com/a/297680). – Zoe Jan 16 '19 at 20:30
  • @Daniel for future reference, [do not translate posts for OP](https://meta.stackoverflow.com/a/297680/6296561); even if you know the language – Zoe Jan 16 '19 at 21:39
1

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".

NoWar
  • 36,338
  • 80
  • 323
  • 498
0

@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.

Henry
  • 17,490
  • 7
  • 63
  • 98
0

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.

user1725145
  • 3,993
  • 2
  • 37
  • 58
0

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.

-1

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.

Giedrius
  • 73
  • 1
  • 6
  • Can you explain what do you mean by "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." I have installed the Samsung's Smart Switch but don't even see the option to factory resetting in there and it looks like just to transfer the file from one device to another... – Vincy Jul 20 '17 at 15:51
  • Open Smart Switch, click "More" and choose "Emergency software recovery and initialization" – Giedrius Jul 20 '17 at 18:12
  • Tried to perform hard reset, spent 30 min - 1 hour, but problem is still there. May I ask you if you have tried this by yourself ? – TarmoPikaro Oct 04 '17 at 21:04
  • I solved the issue on my own device using the steps I posted above. What do you mean exactly by hard reset? Hard reset has a different meaning than factory reset and initialization. – Giedrius Oct 05 '17 at 21:31
  • Did not work for Galaxy S7. Smart Switch says "SM-G930A does not support initializing." – Zsombor Oct 26 '17 at 15:08
  • Looks like there are a lot of different device models. The instructions I posted here worked on my Samsung Galaxy S6 Edge, SM-G925F. The advantage of this method I posted is that you don't need to root your device. If the instructions didn't work, try updating the OS to a later build. The OS build number that works for me right now is NRD90M.G925FXXU5EQBC – Giedrius Oct 29 '17 at 20:56