# Adding SU to AOSP



## MR H3LLMAN

Been trying to figure out how to do this for awhile and have only found 1 outdated guide. If anyone could help me out with either links, suggestion or their own how-to it would be much appreciated. I'm compiling from AOSP source for toro. Thanks in advance guys!


----------



## Lens_Flare

Normally when building from source .....your rom should have root...if not i forgot the method of adding in before but .....
Once rom is compiled and zipped...
Grab su binaries and apk for your device....and add to the bins and apk directories of your rom...flash..and you got root


----------



## yarly

Lens_Flare said:


> Normally when building from source .....your rom should have root...if not i forgot the method of adding in before but .....


Building vanilla AOSP will not have root in the sense most users would think (no super user gui frontend). It will also wipe out your recovery.img unless you remove that part as well. I would reccomend just doing what some ROMs do and build it yourself. CM adds it to their vendor make file to add it to the build compile and also has it as a repository:

https://github.com/C..._apps_Superuser

It could also be done as a prebuilt, which is how some other ROMs do it.


----------



## MR H3LLMAN

yarly said:


> Building vanilla AOSP will not have root in the sense most users would think (no super user gui frontend). It will also wipe out your recovery.img unless you remove that part as well. I would reccomend just doing what some ROMs do and build it yourself. CM adds it to their vendor make file to add it to the build compile and also has it as a repository:
> 
> https://github.com/C..._apps_Superuser
> 
> It could also be done as a prebuilt, which is how some other ROMs do it.


Just to double check, I think I've been over thinking this. Am I right in now thinking that all I have to do is edit my common.mk file to include Su.apk? If that is the case then awesome but I feel like there has to be a couple of additional lines added for permissions or something. First time going this deep into stuff so bare with me haha.


----------



## imnuts

Above is the source for the APK. If you want to maintain compatibility with the version in the Play store, you'll also need to use his signing keys. I grabbed them from CM's android_build repo, but I'm sure there are other places to get them. That is just the apk though, you'll also need the su binary. ChainsDD has that source available as well. You would then just need to also add it to the build tree, I put it, and have also seen it other places, put in the system/ dir of the android source tree. Then you just need to either rename or delete the AOSP version of su or you get a build error. When building a full package, the build system will take care of permissions automatically for you.


----------



## Lens_Flare

Ohhh....oopss
Didnt see it was AOSP.
That it was CM10
Thanks for fixing my statement


----------



## MR H3LLMAN

Alright so I'm finally just now being able to sit down and try this. When imnuts says add it to the build tree, where exactly are we talking? I'm familiar with editing some config make files in vendor but don't have much experience past that. I'm sure I've probably looked right at the specific file before but I need some confirmation... And for the files that yarly linked me, I would place that in the /packages/apps area and edit 'common.mk' to reflect that change?


----------



## imnuts

I don't know if this would work or not, but here is an example of what you would need. Put the below information in a file named local_manifest.xml and put that file in the .repo directory that is with your android source. Again, this may not provide source that compiles without errors, as I do it differently with my source tree.



Code:


<?xml version="1.0" encoding="UTF-8"?><br />
<manifest><br />
  <remote fetch="git://github.com" name="github" /><br />
<br />
  <project path="packages/apps/Superuser" name="ChainsDD/Superuser" remote="github" revision="master" /><br />
  <project path="system/su" name="ChainsDD/su-binary" remote="github" revision="master" /><br />
</manifest>

Once that is done, you need to repo sync, and also edit system/extras/su/Android.mk and rename the local package to something else (like su-old). From there, make sure it is building su and Superuser.apk, and it should pull them in automatically, assuming the source compiles.


----------



## MR H3LLMAN

imnuts said:


> I don't know if this would work or not, but here is an example of what you would need. Put the below information in a file named local_manifest.xml and put that file in the .repo directory that is with your android source. Again, this may not provide source that compiles without errors, as I do it differently with my source tree.
> 
> 
> Code:
> 
> 
> 
> 
> Once that is done, you need to repo sync, and also edit system/extras/su/Android.mk and rename the local package to something else (like su-old). From there, make sure it is building su and Superuser.apk, and it should pull them in automatically, assuming the source compiles.


Rad! Thanks man. I'll give that a try right now and post back with my results. Here goes nothing...


----------



## MR H3LLMAN

Alright I kind of got it working but am abandoning it for the moment to try it again with 4.2 once most of the kinks get worked out. On that note, I know this is a tall order but I'd be cool with a generalized answer. I'm just wondering how you gain knowledge on working with source in general. Not so much from a programming perspective like java or anything but from a file system standpoint like adding in your own vendor the way aokp or cm does and making that reflect in the build process. I've been trying to dig through evey directory and make file I can find to try and see where certain things are added into a build but am kind of at a standstill...

Sent from my Galaxy Nexus


----------



## imnuts

I looked at what others did, how the proprietary files and such were pulled in, and also looked at the device folders and overlays and just figured it out on my own. Google can also help if you get stuck. Find and grep are also good tools when you want to find where things are located.


----------



## yarly

Yeah, no one really writes guides on this kind of stuff (a large inclusive guide at least) for a few reasons:

1) would take too long to detail and cater it to the group of people that would want it.

2) such information changes quite often due to the ever changing nature and whims of google.

3) most people that learn how to work with AOSP just do it in an informal way of experimenting, searching, and playing around that makes it hard to document in writing.


----------



## imnuts

Until you could get a good guide together that details a lot of stuff, you would need to update it again as something will have changed in AOSP. I'm sure you could get it updated eventually, but it would be no easy task keeping it updated. I gained most of my info from looking at two groups initially, then a third. CM (of course) was one place to see how to change and move stuff around. Also, to set up my personal vendor repo, Peter Alfonso has a really good setup to look at IMO for his Bugless Beast builds. I've also started looking at AOKP repos as well, but they didn't have much when I first started playing with the AOSP code.


----------

