使用超级用户权限从源构建/编译Android

时间:2014-05-24 12:49:40

标签: android root

以下情况 - 我有一个Android支持的单板计算机和制造商的android源代码。它可以从它构建一个Android图像。不幸的是,它没有默认的根源。我可以设法获得一个root的shell。但是我也需要应用程序的超级用户权限,这就是我的目标。

起初我试图从 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;
//}

由于这不起作用,我在stackoverflow上找到了这个帖子:Build Android with Superuser并尝试了这部分建议:

  

要在AOSP中嵌入Superuser.apk,您必须获取并构建:

     

su-binary(例如在external /中)和stub / remove system / extras / su包。   超级用户(例如在packages / app /中)

但是我在构建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

有人能告诉我如何修复此错误或其他获取su权限的方法吗?

非常感谢您提前。 :)

1 个答案:

答案 0 :(得分:2)

好的,我发现了问题。对于任何面临同样问题的人:

su.h

中删除以下if命令
#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