SampleSyncAdapter 断点不起作用

发布于 2024-12-21 16:08:25 字数 148 浏览 1 评论 0原文

我正在使用 Eclipse 来了解 SampleSyncAdapter 示例的工作原理。我无法让断点发挥作用。我在多个位置设置了断点,但没有一个被击中。例如,AuthenticatorActivity.onCreate() 永远不会被调用。有人知道为什么吗?

谢谢。

I'm using Eclipse to learn how the SampleSyncAdapter example works. I can't get my breakpoints to work. I set a breakpoint in multiple locations but none get hit. For example, AuthenticatorActivity.onCreate() never get's called. Anyone know why?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

微凉徒眸意 2024-12-28 16:08:25

实际上,同步适配器在配置它的进程中运行。文档建议设置 android:process=":sync",但这只是一个建议。为了进行调试,您可以随时删除此行。

对于 Android Studio + Gradle,您可以考虑在 src/debug/ 中添加清单的调试版本。事实证明,Gradle 插件无法仅合并 android:process 属性,因此您需要分别在 src/release/AndroidManifest.xml 和 src/debug/AndroidManifest.xml 中定义服务和提供程序,以免合并冲突。

Actually, a sync adapter runs in the process in which it is configured. The documentation suggests setting android:process=":sync", but that is only a suggestion. For debugging you can always remove this line.

For Android Studio + Gradle, you might consider adding a debug version of the manifest in src/debug/. Turns out that the Gradle plugin is unable to merge in just the android:process attribute so you need to define the service and provider in src/release/AndroidManifest.xml and src/debug/AndroidManifest.xml separately so there is no merge conflict.

萌能量女王 2024-12-28 16:08:25

SyncAdapter 执行线程发生在生成的后台进程中,而不是发生在应用程序本身的进程中,而应用程序本身就是您附加了 java 调试器的进程。

简单而丑陋的方法:log() 是你的朋友。

更好的方法:首先查看调试服务,并确定是否需要针对这种情况进行调整。

The SyncAdapter thread of execution occurs in a spawned background process, not in the process of your application itself, which is what you have your java debugger attached to.

Simple and ugly way: log() is your friend.

Better way: Start by looking at Debugging a service and find if that needs to be adapted for this case.

荒人说梦 2024-12-28 16:08:25

我遇到了这个问题,解决方案非常简单。如前所述,SyncAdapter 在不同的线程上运行,因此您需要将调试器指向该线程。
在 Android Studio 上,您在 SyncAdapter 类中添加(下面的代码):

android.os.Debug.waitForDebugger();

当您调试应用程序时,同步适配器服务不会自动运行,因此您必须启动它,然后定位该进程。

将调试器附加到 Android 进程(它是绿色错误旁边的图标)

它应该可以正常工作

I had this problem and the solution was quite simple. As said before, the SyncAdapter runs on a different thread so you need to point the debugger to this thread.
On Android Studio you add (code below) inside the SyncAdapter class:

android.os.Debug.waitForDebugger();

When you're debugging your app the sync adapter service won't be running automatically, so you have to start it and then target that process.

Attach debugger to Android Process (It's an icon next to the green bug)

It should work just fine

芸娘子的小脾气 2024-12-28 16:08:25

在 @Eric Woodruff 的回答之后,我得到了这个想法,我与那些想要在 Eclipse 中专门用于同步适配器的调试会话的人分享:
1.切换到DDMS视角
2.在设备/模拟器进程中找到:synch(见图)
3.然后单击绿色错误按钮(调试所选进程:前提是其源项目存在并在工作区中打开)
在此处输入图像描述

这对我来说效果很好,并给了我一个更现实的观点:
在此处输入图像描述

Following @Eric Woodruff answer I got this idea that I share for those who want a debugging session in Eclipse exclusively dedicated to the sync adapter:
1. Switch to DDMS perspective
2. In the device/emulator process locate :synch (see the picture)
3. Then click on the green bug button ( Debug the selected process: provided it's source project is present and opened in the workspace )
enter image description here

this works fine for me and give me a more realistic point of view:
enter image description here

怀念你的温柔 2024-12-28 16:08:25
android:process=":sync"

正如其他答案中给出的那样,效果很好。

最重要的是,如果您对 ContentResolver.requestSync(mAccount, AUTHORITY, settingsBundle) 的调用有任何问题,则您的服务将不会被调用而不会引发任何错误。
您需要仔细检查 Authority 字符串在清单和 xml 以及 java 代码中是否匹配。此外,Account 对象是使用正确的帐户类型正确创建的,并使用以下方法添加到 AccountManager 中:(

accountManager.addAccountExplicitly(newAccount, null, null)

变量名称以官方 android 教程命名 此处

android:process=":sync"

As given in other answers works great.

On top of that, if your call to ContentResolver.requestSync(mAccount, AUTHORITY, settingsBundle) has anything wrong with it, your service won't get called without any errors thrown.
You need to double check that the Authority string is matching in the manifest and xml, and java code. Also the Account object is created correctly with the right account type and added to the AccountManager using:

accountManager.addAccountExplicitly(newAccount, null, null)

(the variable names are named after the official android tutorial here:

萌︼了一个春 2024-12-28 16:08:25

检查了几个答案后,这对我有用

  1. 在清单中使用 :sync 标记流程

  2. 在调试模式下运行

  3. 将断点放置在您想要的位置

  4. 在调试期间按“将调试器附加到 Android 进程”

将调试器附加到 Android 进程

  1. 激活同步一次 - 如果您的同步适配器与某个项目同步(例如联系人),您可以进入设置/帐户和备份/帐户/您的帐户/同步帐户,然后按“立即同步”激活。

  2. 首次激活同步时,您将在“选择进程”窗口中看到您的 packagename:sync。选择它并按“确定”

  3. 下次激活同步时,它将转到您的断点

After checking several answers, this what worked for me

  1. tag process with :sync in manifest

  2. run in debug mode

  3. place your breakpoint where you want

  4. during Debug press "Attach Debugger to Android process"

Attach Debugger to Android process

  1. Activate the sync once - if your sync adapter is synced with an item (e.g. contacts), you can go to settings/Accounts and backup/Accounts/Your Acount/ Sync acount and press "Sync Now" to activate.

  2. When sync first activated, you will see your packagename:sync at the "Choose process" window. Choose it and press OK

  3. Next time the sync is activated, it will go to your breakpoint

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文