Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build/compile Android from source with Superuser privileges

Tags:

android

root

following situation - I have got a Single Board Computer with Android support and the android source code from the manufacturer. It works to build an android image from it at all. Unfortunately, it's not rooted by default. I could manage to get a rooted shell. But I also need superuser privileges for the apps and that's the point where I am struggeling.

At first I tried to comment out following lines from system/extras/su/su.c:

//if (myuid != AID_ROOT && myuid != AID_SHELL) {
//    fprintf(stderr,"su: uid %d not allowed to su\n", myuid);
//    return 1;
//}

//if(setgid(gid) || setuid(uid)) {
//    fprintf(stderr,"su: permission denied\n");
//    return 1;
//}

As this didn't work, I found this thread here on stackoverflow: Build Android with Superuser and tried this part of the suggestion:

To embed Superuser.apk in AOSP, you have to fetch and build:

su-binary (e.g. in external/) and stub/remove system/extras/su package. Superuser (e.g. in packages/app/)

But I am running in errors while building android:

ctarget Dex: core-tests-hostdex
../arm-linux-androideabi/bin/ld: out/target/product/.../obj/EXECUTABLES/su_intermediates/su.o: in function deny:external/su-binary-master/su.c:287: error: undefined reference to 'LOGW'
../arm-linux-androideabi/bin/ld: out/target/product/.../obj/EXECUTABLES/su_intermediates/su.o: in function allow:external/su-binary-master/su.c:319: error: undefined reference to 'LOGE'
../arm-linux-androideabi/bin/ld: out/target/product/.../obj/EXECUTABLES/su_intermediates/su.o: in function allow:external/su-binary-master/su.c:330: error: undefined reference to 'LOGE'
../arm-linux-androideabi/bin/ld: out/target/product/.../obj/EXECUTABLES/su_intermediates/su.o: in function allow:external/su-binary-master/su.c:338: error: undefined reference to 'LOGD'
../arm-linux-androideabi/bin/ld: out/target/product/.../obj/EXECUTABLES/su_intermediates/su.o: in function allow:external/su-binary-master/su.c:352: error: undefined reference to 'LOGE'
../arm-linux-androideabi/bin/ld: out/target/product/.../obj/EXECUTABLES/su_intermediates/su.o: in function main:external/su-binary-master/su.c:440: error: undefined reference to 'LOGE'
../arm-linux-androideabi/bin/ld: out/target/product/.../obj/EXECUTABLES/su_intermediates/su.o: in function main:external/su-binary-master/su.c:582: error: undefined reference to 'LOGW'
../arm-linux-androideabi/bin/ld: out/target/product/.../obj/EXECUTABLES/su_intermediates/db.o: in function database_check:external/su-binary-master/db.c:31: error: undefined reference to 'LOGD'
../arm-linux-androideabi/bin/ld: out/target/product/.../obj/EXECUTABLES/su_intermediates/db.o: in function database_check:external/su-binary-master/db.c:35: error: undefined reference to 'LOGD'
../arm-linux-androideabi/bin/ld: out/target/product/.../obj/EXECUTABLES/su_intermediates/db.o: in function database_check:external/su-binary-master/db.c:39: error: undefined reference to 'LOGD'
collect2: ld returned 1 exit status
make: *** [out/target/product/.../obj/EXECUTABLES/su_intermediates/LINKED/su] Error 1

Could anyone tell me how to fix this error or another way to get su privileges, please?

Thank you very much in advance. :)

like image 280
user3671659 Avatar asked Oct 31 '22 23:10

user3671659


1 Answers

Okay, I found the problem. For anyone who faces the same problem:

Remove the following if-command from su.h:

#if 0
#undef LOGE
#define LOGE(fmt,args...) fprintf(stderr, fmt, ##args)
#undef LOGD
#define LOGD(fmt,args...) fprintf(stderr, fmt, ##args)
#undef LOGW
#define LOGW(fmt,args...) fprintf(stderr, fmt, ##args)
#endif
like image 69
user3671659 Avatar answered Nov 12 '22 10:11

user3671659