run-as Package 'a.b.c' is unknown - Galaxy S4 Jellybean or Android 4.3

做~自己de王妃 提交于 2019-11-27 03:58:04

问题


I cannot run run-as (or ndk-gdb) for the Galaxy S4 running Jellybean 4.2.2.

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

There are multiple answers for this issue for pre-ICS devices, but those seem to have been fixed in ICS.

Update - Aug 2013: After initially appearing on the Galaxy S4 with Jellybean 4.2.2, the run-as issue now seems to be on all 4.3 devices. See this Android bug.

See the acknowledged Android issue here.

Update - Nov 2013: Google posted the patches that fix run-as in Android 4.4.


回答1:


Found success by adding this to the 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");
    }
}

Then I wrapped startGdbServer in an Android service and updating the ndk-gdb script to start the server instead of the run-as command.

Here's the manifest addition:

<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>

Here are the relevant ndk-gdb changes (in 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)



回答2:


One thing that ended up fixing my Nexus 7 from doing this, is installing different ADB drivers. I also re-flashed the device (though I am not sure if this was indeed what fixed it). As mentioned in another answer (mine) was that rooting would be required - when in fact, it did not help in my case either.




回答3:


In my case it was a problem of core app:

shell@android:/ $ run-as com.android.phone transfer_bugreport ls
run-as: Package 'com.android.phone' is unknown

Package which have in AndroidManifest.xml in <maninfest> tag coreApp="true" are excluded from /data/system/packages.list and thus really unknown for run-as.




回答4:


There is a known issue with the latest version of Nexus 7. Simply downgrade to 4.2 (or get 4.3 without the mini-update) and you should be fine. There's a discussion here about it:

http://code.google.com/p/android/issues/detail?id=58373



来源:https://stackoverflow.com/questions/17219906/run-as-package-a-b-c-is-unknown-galaxy-s4-jellybean-or-android-4-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!