简体   繁体   English

调试异步任务时,Android Studio中的奇怪调试器行为

[英]Strange debugger behaviour in Android studio when debugging an Async task

I've been trying to use the Android Studio breakpoints in order to debug my code, but they are giving me extremely weird behaviour. 我一直在尝试使用Android Studio断点来调试我的代码,但是它们给了我极其奇怪的行为。 For example I'm trying to debug the following snippet: 例如,我正在尝试调试以下代码段:

new AsyncTask<Void, Void, Exception>() {
    @Override
    protected Exception doInBackground(Void... params) {
        try {
            Assets assets = new Assets(MainActivity.this);
            File assetDir = assets.syncAssets();
            setupRecognizer(assetDir);
        } catch (IOException e) {
            return e;
        }
        return null;
    }

    @Override
    protected void onPostExecute(Exception result) {
        if (result != null) {
            ((TextView) findViewById(R.id.textView))
                    .setText("Failed to init recognizer " + result);
        } else {
            switchSearch(KWS_SEARCH);
        }
    }
}.execute();

I put a breakpoint on the line 我在网上设置了一个断点

Assets assets = new Assets(MainActivity.this);

And then I say "Step into". 然后我说“进入”。 This takes me to a "decompiled class file" and the following code snippet: 这将带我到“反编译的类文件”和以下代码片段:

public Assets(Context context) throws IOException {
    File appDir = context.getExternalFilesDir((String)null);
    if(null == appDir) {
        throw new IOException("cannot get external files dir, external storage state is " + Environment.getExternalStorageState());
    } else {
        this.externalDir = new File(appDir, "sync");
        this.assetManager = context.getAssets();
    }
}

Which is completely expected and reasonable. 这是完全可以预期和合理的。 After this I try to step into the line 在此之后,我尝试进入生产线

File appDir = context.getExternalFilesDir((String)null);

And then things get really weird. 然后事情变得很奇怪。 First I get taken to a new file where I land on a blank line in between two methods. 首先,我进入一个新文件,在这两种方法之间的空白行上都找到了新文件。 When I try to step into the blank line I get bounced to another file where execution has halted at the closing curly brace of another method. 当我尝试进入空白行时,我跳到另一个文件,该文件的执行在另一个方法的右花括号处暂停。 Then I step into that curly brace and I get taken to another blank line between two methods in another file. 然后进入花括号,然后转到另一个文件中两个方法之间的另一个空白行。 When I step into that, I get taken to the very next line, which is simply an @override annotation. 当我进入其中时,我会转到下一行,它只是一个@override注释。 Stepping into that takes me to the closing curly brace of an if statement in yet another file. 进入该目录后,我将进入另一个文件中if语句的大括号。

This weird behaviour continues on and on and I can't make sense of it. 这种奇怪的行为一直持续下去,我无法理解。 At one point the debugger even seems to pause execution in the middle of a comment! 有时,调试器甚至似乎在注释的中间暂停执行! How is that even possible? 这怎么可能呢? Does anyone know why this is happening? 有人知道为什么会这样吗? Does it have something to do with the fact that I am debugging an AsyncTask? 它与我调试AsyncTask有关吗?

(Note that I have repeated this debugging process four times and been presented with the same strange behaviour every time) (请注意,我已重复此调试过程四次,并且每次都出现相同的奇怪行为)

Is not a problem in Debug. 在调试中不是问题。 When Debug pause in blank space or comment is just that the original source code class and the source provided is not synchronized or is not at the same version. 当“调试”在空格或注释中暂停时,仅表示原始源代码类和提供的源未同步或版本不同。

EDIT: 编辑:

Let me explain you with an example. 让我用一个例子来解释一下。 You've a third party library xxx-1.1.jar, and you want to debug inside code of this library so you googled and find the source xxx-1.1-source.jar of this jar. 您具有第三方库xxx-1.1.jar,并且想调试该库的内部代码,因此您用Google搜索并找到了此jar的源xxx-1.1-source.jar。 But for some reason developer of xxx-1.1-source.jar packaged this source 2 hours after create xxx-1.1.jar and he add some comment at the beginning of some class that you want to debug so, at this point when you debug xxx-1.1.jar using the code provided by xxx-1.1-source.jar the source code don't match exactly. 但是出于某种原因,xxx-1.1-source.jar的开发人员在创建xxx-1.1.jar的两个小时后打包了此源代码,并且他在要调试的某个类的开头添加了一些注释,因此在此时调试xxx -1.1.jar使用xxx-1.1-source.jar提供的代码,源代码不完全匹配。

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 异步任务停止工作,在使用断点进行调试时可以工作-Android - Async Task Stops Working, works when debugging with break points - Android 使用Eclipse Debugger调试Eclipse CDT时的奇怪行为 - Strange behavior when debugging Eclipse CDT with Eclipse Debugger 如果不调试,为什么 Android Studio 会显示“等待调试器”? - Why Android Studio says "Waiting For Debugger" if am NOT debugging? Android Studio - UI 线程未使用异步任务更新 - Android Studio - UI Thread not updating with Async Task Expandablelistview中的奇怪行为 - Android - Strange behaviour in Expandablelistview - Android 调试AsyncTask-奇怪的行为,调试跳入代码 - Debugging AsyncTask - strange behaviour, debug jumping into the code 从睡眠回来时Android App的异常行为 - Android App strange behaviour when comeing back from sleep Android Studio - 在一个异步任务中从 2 个 url 下载 JSON 数据 - Android Studio - download JSON data from 2 urls in one Async Task Android SharedPreferences中奇怪的无法解释的行为 - Strange unexplained behaviour in SharedPreferences Android Android-CardView给出奇怪的行为 - Android - CardView give strange behaviour
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM