Android 错误打开跟踪文件:没有这样的文件或目录 (2)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11446049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:26:59  来源:igfitidea点击:

error opening trace file: No such file or directory (2)

androideclipseandroid-emulatorlogcatandroid-sdcard

提问by Ankit Jain

I am getting the above error:

我收到上述错误:

error opening trace file: No such file or directory (2)

错误打开跟踪文件:没有这样的文件或目录 (2)

when I run my android application on the emulator. Can someone tell me what could be the possible reason for this?

当我在模拟器上运行我的 android 应用程序时。有人能告诉我这可能是什么原因吗?

I am using android-sdk-20 and below lines are added to AndroidManifest.xml

我正在使用 android-sdk-20 并将以下行添加到 AndroidManifest.xml

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="15" />

I have also added the line:

我还添加了以下行:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

since I thought that there may be some issue with writing to the sd card.

因为我认为写入 SD 卡可能存在一些问题。

回答by Aurumque

It happens because you have not installed the minSdkVersion or targetSdkVersion in you're computer. I've tested it right now.

发生这种情况是因为您尚未在计算机中安装 minSdkVersion 或 targetSdkVersion。我现在已经测试过了。

For example, if you have those lines in your Manifest.xml:

例如,如果您的 Manifest.xml 中有这些行:

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />

And you have installed only the API17 in your computer, it will report you an error. If you want to test it, try installing the other API version (in this case, API 8).

而你的电脑只安装了API17,它会报错。如果您想对其进行测试,请尝试安装其他 API 版本(在本例中为 API 8)。

Even so, it's not an important error. It doesn't mean that your app is wrong.

即便如此,这也不是一个重要的错误。这并不意味着您的应用程序是错误的。

Sorry about my expression. English is not my language. Bye!

对不起我的表达。英语不是我的语言。再见!

回答by Vrashabh Irde

I think this is the problem

我认为这是问题所在

A little background

一点背景

Traceview is a graphical viewer for execution logs that you create by using the Debug class to log tracing information in your code. Traceview can help you debug your application and profile its performance. Enabling it creates a .tracefile in the sdcard root folder which can then be extracted by ADB and processed by traceview bat file for processing. It also can get added by the DDMS.

Traceview 是一个图形查看器,用于查看您通过使用 Debug 类在代码中记录跟踪信息而创建的执行日志。Traceview 可以帮助您调试应用程序并分析其性能。启用它会.trace在 sdcard 根文件夹中创建一个文件,然后可以由 ADB 提取并由 traceview bat 文件处理以进行处理。它也可以由 DDMS 添加。

It is a system used internally by the logger. In general unless you are using traceview to extract the trace file this error shouldnt bother you.You should look at error/logs directly related to your application

它是记录器内部使用的系统。通常,除非您使用 traceview 提取跟踪文件,否则此错误不会打扰您。您应该查看与您的应用程序直接相关的错误/日志

How do I enable it:

我如何启用它:

There are two ways to generate trace logs:

  1. Include the Debug class in your code and call its methods such as startMethodTracing()and stopMethodTracing(), to start and stop logging of trace information to disk. This option is very precise because you can specify exactly where to start and stop logging trace data in your code.

  2. Use the method profiling feature of DDMS to generate trace logs. This option is less precise because you do not modify code, but rather specify when to start and stop logging with DDMS. Although you have less control on exactly where logging starts and stops, this option is useful if you don't have access to the application's code, or if you do not need precise log timing.

有两种方法可以生成跟踪日志:

  1. 在您的代码中包含 Debug 类并调用其方法(例如startMethodTracing()stopMethodTracing())以启动和停止将跟踪信息记录到磁盘。此选项非常精确,因为您可以在代码中准确指定开始和停止记录跟踪数据的位置。

  2. 使用 DDMS 的方法分析功能生成跟踪日志。此选项不太精确,因为您不修改代码,而是指定何时开始和停止使用 DDMS 进行日志记录。尽管您对记录开始和停止的确切位置的控制较少,但如果您无权访问应用程序的代码,或者您不需要精确的日志计时,则此选项很有用。

But the following restrictions exist for the above

但上述情况存在以下限制

If you are using the Debug class, your application must have permission to write to external storage (WRITE_EXTERNAL_STORAGE).

If you are using DDMS: Android 2.1 and earlier devices must have an SD card present and your application must have permission to write to the SD card. Android 2.2 and later devices do not need an SD card. The trace log files are streamed directly to your development machine.

如果您使用的是 Debug 类,则您的应用程序必须具有写入外部存储 ( WRITE_EXTERNAL_STORAGE) 的权限。

如果您使用 DDMS:Android 2.1 和更早版本的设备必须有 SD 卡,并且您的应用程序必须具有写入 SD 卡的权限。Android 2.2 及更高版本的设备不需要 SD 卡。跟踪日志文件直接流式传输到您的开发机器。

So in essence the traceFile access requires two things

所以本质上,traceFile 访问需要两件事

1.) Permission to write a trace log file i.e. WRITE_EXTERNAL_STORAGEand READ_EXTERNAL_STORAGEfor good measure

2.) An emulator with an SDCard attached with sufficient space. The doc doesnt say if this is only for DDMS but also for debug, so I am assuming this is also true for debugging via the application.

1)权限写一个跟踪日志文件,即WRITE_EXTERNAL_STORAGEREAD_EXTERNAL_STORAGE的好办法

2.) 带有足够空间的 SDCard 的仿真器。该文档没有说明这是否仅适用于 DDMS,也适用于调试,所以我假设这对于通过应用程序进行调试也是如此。

What do I do with this error:

我该怎么办这个错误:

Now the error is essentially a fall out of either not having the sdcard path to create a tracefile or not having permission to access it. This is an old thread, but the dev behind the bounty, check if are meeting the two prerequisites. You can then go search for the .tracefile in the sdcard folder in your emulator. If it exists it shouldn't be giving you this problem, if it doesnt try creating it by adding the startMethodTracingto your app.
I'm not sure why it automatically looks for this file when the logger kicks in. I think when an error/log event occurs , the logger internally tries to write to trace file and does not find it, in which case it throws the error.Having scoured through the docs, I don't find too many references to why this is automatically on. But in general this doesn't affect you directly, you should check direct application logs/errors. Also as an aside Android 2.2 and later devices do not need an SD card for DDMS trace logging. The trace log files are streamed directly to your development machine.

现在该错误本质上是由于没有创建跟踪文件的 sdcard 路径或没有访问它的权限。这是一个旧线程,但赏金背后的开发人员,请检查是否满足两个先决条件。然后,您可以.trace在模拟器的 sdcard 文件夹中搜索该文件。如果它存在,它不应该给你这个问题,如果它不尝试通过将它添加startMethodTracing到你的应用程序来创建它。
我不确定为什么它会在记录器启动时自动查找此文件。我认为当发生错误/日志事件时,记录器会在内部尝试写入跟踪文件但找不到它,在这种情况下它会抛出错误. 浏览文档后,我没有找到太多关于为什么会自动打开的参考。但总的来说,这不会直接影响您,您应该检查直接应用程序日志/错误。另外,Android 2.2 及更高版本的设备不需要 SD 卡来进行 DDMS 跟踪记录。跟踪日志文件直接流式传输到您的开发机器。

Additional information on Traceview:

有关 Traceview 的其他信息:

Copying Trace Files to a Host Machine

After your application has run and the system has created your trace files .trace on a device or emulator, you must copy those files to your development computer. You can use adb pull to copy the files. Here's an example that shows how to copy an example file, calc.trace, from the default location on the emulator to the /tmp directory on the emulator host machine:

adb pull /sdcard/calc.trace /tmp Viewing Trace Files in Traceview To run Traceview and view the trace files, enter traceview . For example, to run Traceview on the example files copied in the previous section, use:

traceview /tmp/calc Note: If you are trying to view the trace logs of an application that is built with ProGuard enabled (release mode build), some method and member names might be obfuscated. You can use the Proguard mapping.txt file to figure out the original unobfuscated names. For more information on this file, see the Proguard documentation.

将跟踪文件复制到主机

在您的应用程序运行并且系统在设备或模拟器上创建您的跟踪文件 .trace 之后,您必须将这些文件复制到您的开发计算机。您可以使用 adb pull 来复制文件。下面的示例展示了如何将示例文件 calc.trace 从模拟器上的默认位置复制到模拟器主机上的 /tmp 目录:

adb pull /sdcard/calc.trace /tmp 在 Traceview 中查看跟踪文件 要运行 Traceview 并查看跟踪文件,请输入 traceview 。例如,要对上一节中复制的示例文件运行 Traceview,请使用:

traceview /tmp/calc 注意:如果您尝试查看在启用 ProGuard 的情况下构建的应用程序的跟踪日志(发布模式构建),则某些方法和成员名称可能会被混淆。您可以使用 Proguard mapping.txt 文件找出未混淆的原始名称。有关此文件的更多信息,请参阅 Proguard 文档。

I think any other answer regarding positioning of oncreatestatements or removing uses-sdkare not related, but this is Android and I could be wrong. Would be useful to redirect this question to an android engineer or post it as a bug

我认为关于oncreate语句定位或删除的任何其他答案uses-sdk都不相关,但这是 Android,我可能是错的。将此问题重定向到 android 工程师或将其作为错误发布会很有用

More in the docs

文档中的更多内容

回答by ANemati

Try removing the uses-sdkpart form AndroidManifest.xmlfile. it worked for me!

尝试删除uses-sdk零件表格AndroidManifest.xml文件。它对我有用!

Don't use the Android Virtual Device with too low configuration. Let it be medium.

不要使用配置太低的安卓虚拟设备。让它中等。

回答by Sudip

Write all your code below this 2 lines:-

在这两行下面写下你的所有代码:-

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

It worked for me without re-installing again.

它对我有用而无需再次重新安装。

回答by Kyle Falconer

I didn't want to reinstall everything because I have so many SDK versions installed and my development environment is set up just right. Getting it set up again takes way too long.

我不想重新安装所有东西,因为我安装了这么多 SDK 版本,而且我的开发环境设置得恰到好处。重新设置它需要太长时间。

What worked for me was deleting, then re-creating the Android Virtual Device, being certain to put in a value for SD Card Size (I used 200 MiB).

对我有用的是删除,然后重新创建 Android 虚拟设备,确保输入 SD 卡大小的值(我使用了 200 MiB)。

screenshot of the AVD creation screen

screenshot of the AVD creation screen

Additional information:

附加信息:

while the above does fix the problem temporarily, it is recurring. I just tried my application within Android Studio and saw this in the output log which I did not notice before in Eclipse:

虽然上述确实暂时解决了问题,但它会反复出现。我刚刚在 Android Studio 中尝试了我的应用程序,并在输出日志中看到了这一点,而我之前在 Eclipse 中没有注意到:

"/Applications/Android Studio.app/sdk/tools/emulator" -avd AVD_for_Nexus_S_by_Google -netspeed full -netdelay none

WARNING: Data partition already in use. Changes will not persist!
WARNING: SD Card image already in use: /Users/[user]/.android/avd/AVD_for_Nexus_S_by_Google.avd/sdcard.img
ko:Snapshot storage already in use: /Users/[user]/.android/avd/AVD_for_Nexus_S_by_Google.avd/snapshots.img

I suspect that changes to the log are not saving to the SD Card, so when LogCat tries to access the logs, they aren't there, causing the error message. The act of deleting the AVD and re-creating it removes the files, and the next launch is a fresh launch, allowing LogCat to access the virtual SD Card.

我怀疑对日志的更改没有保存到 SD 卡,因此当 LogCat 尝试访问日志时,它们不存在,从而导致错误消息。删除 AVD 并重新创建它的行为会删除文件,下次启动是全新启动,允许 LogCat 访问虚拟 SD 卡。

回答by Erol

You will not have access to your real sd card in emulator. You will have to follow the steps in this tutorialto direct your emulator to a directory on your development environment acting as your SD card.

您将无法在模拟器中访问真正的 SD 卡。您必须按照本教程中的步骤将模拟器定向到开发环境中充当 SD 卡的目录。

回答by eMPee584

Actually, the problem is that either /sys/kernel/debugis not mounted, or that the running kernel has no ftrace tracers compiled in so that /sys/kernel/debug/tracingis unavailable. This is the code throwing the error (platform_frameworks_native/libs/utils/Trace.cpp):

实际上,问题在于/sys/kernel/debug没有挂载,或者正在运行的内核没有编译 ftrace 跟踪器,因此/sys/kernel/debug/tracing不可用。这是抛出错误 ( platform_frameworks_native/libs/utils/Trace.cpp)的代码:

void Tracer::init() {
    Mutex::Autolock lock(sMutex);

    if (!sIsReady) {
        add_sysprop_change_callback(changeCallback, 0);

        const char* const traceFileName =
                "/sys/kernel/debug/tracing/trace_marker";
        sTraceFD = open(traceFileName, O_WRONLY);
        if (sTraceFD == -1) {
            ALOGE("error opening trace file: %s (%d)", strerror(errno), errno);
            sEnabledTags = 0;   // no tracing can occur
        } else {
            loadSystemProperty();
        }

        android_atomic_release_store(1, &sIsReady);
    }
}

The log message could definitely be a bit more informative.

日志消息肯定可以提供更多信息。