10

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.

Tin Megali
  • 771
  • 5
  • 25
Mitch
  • 1,716
  • 3
  • 25
  • 41

6 Answers6

23

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.

Eric Woodruff
  • 6,380
  • 3
  • 36
  • 33
15

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.

Community
  • 1
  • 1
jcwenger
  • 11,383
  • 1
  • 53
  • 65
  • Thanks. I suspected it had something to do with which process but had no actual info to back that hypothesis. I'm unfamiliar with debuggers that care about which process when it comes to a breakpoint. I really dislike the log() in Android. I'm used to a much more sophisticated logging that allows a programmer much greater control, including the ability to selectively remove the logging code in release builds. Thanks, I'll look at the link. – Mitch Dec 20 '11 at 20:34
  • 9
    FYI the SyncAdapter documentation example has a `android:process=":sync"` attribute on the Service's entry in the AndroidManifest.xml. During debugging, it can be easier to drop this attribute so that the service will run in your main process to which your IDE is already attached. – Tobias Dec 15 '13 at 10:00
  • @Eric, It probably was when I answered it in 2011. It's probably not, today. :) – jcwenger Jul 24 '15 at 16:33
3

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

Tin Megali
  • 771
  • 5
  • 25
0

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

Franco Rondini
  • 10,841
  • 8
  • 51
  • 77
0
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:

Justin Liu
  • 138
  • 1
  • 9
0

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

epic
  • 1,333
  • 1
  • 13
  • 27