android - run-as 包 'a.b.c' 未知 - Galaxy S4 Jellybean 或 Android 4.3

标签 android android-ndk gdb android-4.3-jelly-bean ndk-gdb

我无法为运行 Jellybean 4.2.2 的 Galaxy S4 运行 run-as(或 ndk-gdb)。

~  $ adb shell
shell@android:/ $ run-as a.b.c ls
run-as: Package 'a.b.c' is unknown

对于 ICS 之前的设备,此问题有多个答案,但这些问题似乎已在 ICS 中修复。

更新 - 2013 年 8 月:最初出现在装有 Jellybean 4.2.2 的 Galaxy S4 上后,运行方式问题现在似乎出现在所有 4.3 设备上。看这个Android bug .

请参阅公认的 Android 问题 here .

更新 - 2013 年 11 月:Google 发布了 patches修复了 Android 4.4 中的运行方式。

最佳答案

通过将此添加到 Activity 中找到成功:

private void startGdbServer() {   
    try {
        new ProcessBuilder()
        .command(getFilesDir().getParent() + "/lib/gdbserver", "tcp:5039", "--attach" ,"" + android.os.Process.myPid())
        .redirectErrorStream(true)
        .start();
    } catch (IOException e) {
        Log.e(TAG, "IOException failed to start gdbserver");
    }
}

然后我将 startGdbServer 包装在一个 Android 服务中并更新 ndk-gdb 脚本以启动服务器而不是 run-as 命令。

这是明显的补充:

<service android:enabled="true" android:name="com.apportable.activity.GdbServerService"
    android:label="@string/app_name" android:icon="@drawable/icon">
    <intent-filter >
        <action android:name="apportable.FoundationTests.GdbServerService" />
    </intent-filter>
</service>

以下是相关的 ndk-gdb 更改(在 python 中):

    remote_gdbserver = '/data/data/' + env['APPLICATION_IDENTIFIER'] + '/lib/gdbserver'

    print "Attaching to pid " + pid
    # Android 4.2 requires the --user 0 option. Earlier versions cannot have it

    results = env.Execute([env['ADB'], 'shell', 'am'])
    if "--user" in results:
        user_option = "--user 0"
    else:
        user_option = ""

    adb.AsyncShell(env, 'am startservice ' + user_option + ' -a ' + env['APPLICATION_IDENTIFIER'] + '.GdbServerService --es gdbserver_name ' + remote_gdbserver + ' --ei gdbserver_port ' + str(env['ANDROID_REMOTE_DEBUG_PORT']))

    # HACK: magic number. ensure the gdb server is actually up and running
    time.sleep(2)  # 1 is usually enough, but not always, like after reboot or with heavy system load

    adb.Forward(env, env['ANDROID_LOCAL_DEBUG_PORT'], env['ANDROID_REMOTE_DEBUG_PORT'])

    adb.Pull(env, process_path, '/system/bin/app_process')

    setup_path = '"' + setup_path + '"'

    if env['CGDB'] is not None:
        cmd = [env['CGDB'], '-d', env['GDB'], '--', '-x', setup_path]
    else:
        cmd = [env['GDB'], '-x', setup_path]

    env.RunCommand(cmd)

关于android - run-as 包 'a.b.c' 未知 - Galaxy S4 Jellybean 或 Android 4.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33830153/

相关文章:

android - ListView 中的 getSelectedItem() 的目的是什么

android - 为什么Android Bound Services文档提示IBinder不能跨进程使用?

android - 为什么我的数据很大时会出现Activity暂停超时异常?

android - 学习 ffmpeg 的一些链接和教程

android - 找不到 Javah 错误 android.app.Activity

android - Superpowered API - SuperpoweredDecoder::decode 不为文件末尾返回 0

c++ - 如何在 gdb 中将 void 指针转换为 unique_ptr<T>?

android - NumberPicker 在 DialogFragment 中不起作用

c - 启动调试器失败 : No executable specified, 使用 `target exec'

c++ - GDB分步调试两个线程