1.PC通过ADB连接手机后,执行adb shell uiautomator runtest XXX.jar -c com.XXX,可以正常运行uiautomator的jar文件程序。
2.通过APK调用以下方法一,在android 4.4和android 5.0上都提示:
Error running exec(). Command: [su] Working Directory: null Environment: null
通过方法二,在android4.4上可以正常调用uiautomator程序,但是在android 5.0上却无法调用uiautomator jar,也不会报错。方法一:
public boolean runRootCommand(String command){
     Process process = null;
     DataOutputStream os = null;
     try{
     process = Runtime.getRuntime().exec("su");
     os = new DataOutputStream(process.getOutputStream());
     os.writeBytes(command+"\n");
     os.writeBytes("exit\n");
     os.flush();
     process.waitFor();
     }catch(Exception e){
     Log.e("**dbg***", e.getMessage());
     return false;
     }finally{
     try{
     if(os!=null){
     os.close();
     }
     process.destroy();
     }catch(Exception e){}
     }
     return true;
    }方法二:
public void startOtherProcess(int maxTime,String exec){
     try
{
final Process starter=Runtime.getRuntime().exec(exec);
final BufferedReader br = new BufferedReader(new InputStreamReader(starter.getInputStream()));
String line=null;
while((line=br.readLine())!=null)
{}
if(starter!=null){
try {
br.close();
starter.destroy();
} catch (Exception e) {
e.printStackTrace();
}
}
}catch(Throwable e){
Log.e("**dbg***", e.getMessage());
}
    }
PS:APK使用的是:android:sharedUserId="android.uid.system",eclipse—运行—android application打包生成APK时,用的也是公司提供的系统签名文件(签名文件是OK的)。
开始怀疑手机没有root,把手机root开关也打开了。但是/system/bin目录下没有su文件
C:\Documents and Settings\Administrator>adb shell
root@A51:/ # cd /system/bin
cd /system/bin
root@A51:/system/bin # ls
ls
ATFWD-daemon
PktRspTest
StoreKeybox
WifiLogger_app
adb
……
求大神支招,问题到底出现在哪里了?怎样在android 5.0上也能通过APK启动uiautomator?

解决方案 »

  1.   

    你在adb 命令下,显示#表明手机具有root权限,运行su没反应,表明手机没有su文件,你可以自己push su文件到/system/bin/目录下,但是push前需要执行adb remount进行挂载,然后修改su的权限,chmod命令,然后运行su就可以了
      

  2.   

    对不起,最近比较忙,都没有上论坛,刚看到大家的私信。这个问题,具体我也不是很清楚。因为我们是测试自己公司的手机,处理方法是开发编译测试版本时,把我们的测试APK内置,并赋予shell用户权限。这个启动uiautomator的问题就解决了。如果是其他公司的手机,即使root了,也不行,具体原因我也还不清楚。如果有了更好的解决办法,我再分享给大家。
      

  3.   

    http://ask.csdn.net/questions/186258#answer_475687