Why No android.content.SyncAdapter meta-data regis

2019-07-19 05:00发布

I am following the SampleSyncAdapter and upon startup, it appears that my SyncAdapter is not configured correctly. It reports an error trying to load its meta-data. How can I isolate the problem? You can see the other accounts in the system that register correctly.

Logcat:

12-21 17:10:50.667 W/PackageManager(  121): Unable to load service info ResolveInfo{4605dcd0 com.myapp.syncadapter.MySyncAdapter p=0 o=0 m=0x108000}
12-21 17:10:50.667 W/PackageManager(  121): org.xmlpull.v1.XmlPullParserException: No android.content.SyncAdapter meta-data
12-21 17:10:50.667 W/PackageManager(  121):     at android.content.pm.RegisteredServicesCache.parseServiceInfo(RegisteredServicesCache.java:391)
12-21 17:10:50.667 W/PackageManager(  121):     at android.content.pm.RegisteredServicesCache.generateServicesMap(RegisteredServicesCache.java:260)
12-21 17:10:50.667 W/PackageManager(  121):     at android.content.pm.RegisteredServicesCache$1.onReceive(RegisteredServicesCache.java:110)
12-21 17:10:50.667 W/PackageManager(  121):     at android.app.ActivityThread$PackageInfo$ReceiverDispatcher$Args.run(ActivityThread.java:892)
12-21 17:10:50.667 W/PackageManager(  121):     at android.os.Handler.handleCallback(Handler.java:587)
12-21 17:10:50.667 W/PackageManager(  121):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-21 17:10:50.667 W/PackageManager(  121):     at android.os.Looper.loop(Looper.java:123)
12-21 17:10:50.667 W/PackageManager(  121):     at com.android.server.ServerThread.run(SystemServer.java:570)
12-21 17:10:50.747 D/Sources (  294): Creating external source for type=com.skype.contacts.sync, packageName=com.skype.raider
12-21 17:10:50.747 D/Sources (  294): Creating external source for type=com.twitter.android.auth.login, packageName=com.twitter.android
12-21 17:10:50.747 D/Sources (  294): Creating external source for type=com.example.android.samplesync, packageName=com.example.android.samplesync
12-21 17:10:50.747 W/PackageManager(  121): Unable to load service info ResolveInfo{460504b0 com.myapp.syncadapter.MySyncAdapter p=0 o=0 m=0x108000}
12-21 17:10:50.747 W/PackageManager(  121): org.xmlpull.v1.XmlPullParserException: No android.content.SyncAdapter meta-data
12-21 17:10:50.747 W/PackageManager(  121):     at android.content.pm.RegisteredServicesCache.parseServiceInfo(RegisteredServicesCache.java:391)
12-21 17:10:50.747 W/PackageManager(  121):     at android.content.pm.RegisteredServicesCache.generateServicesMap(RegisteredServicesCache.java:260)
12-21 17:10:50.747 W/PackageManager(  121):     at android.content.pm.RegisteredServicesCache$1.onReceive(RegisteredServicesCache.java:110)
12-21 17:10:50.747 W/PackageManager(  121):     at android.app.ActivityThread$PackageInfo$ReceiverDispatcher$Args.run(ActivityThread.java:892)
12-21 17:10:50.747 W/PackageManager(  121):     at android.os.Handler.handleCallback(Handler.java:587)
12-21 17:10:50.747 W/PackageManager(  121):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-21 17:10:50.747 W/PackageManager(  121):     at android.os.Looper.loop(Looper.java:123)
12-21 17:10:50.747 W/PackageManager(  121):     at com.android.server.ServerThread.run(SystemServer.java:570)

Also note, I have tried to force mis-configuration to see if I could change the error in a way that would point out my flaw. Unfortunately, most of the misconfigurations are caught by the (pre)compiler.

I managed to find this logcat entry after an uninstall/install which corresponds to my meta-data node inside the AndroidManifest.xml for the Sync Adapter's service entry. It may be a very important clue that I am investigating.

12-21 18:46:36.026 D/AndroidRuntime(28641): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
12-21 18:46:36.026 D/AndroidRuntime(28641): CheckJNI is OFF
12-21 18:46:36.106 D/AndroidRuntime(28641): --- registering native functions ---
12-21 18:46:36.836 D/PackageParser(  121): Scanning package: /data/app/vmdl13904.tmp
12-21 18:46:36.856 W/PackageParser(  121): Unknown element under <intent-filter>: meta-data at /data/app/vmdl13904.tmp Binary XML file line #254
12-21 18:46:36.856 W/PackageParser(  121): Unknown element under <intent-filter>: meta-data at /data/app/vmdl13904.tmp Binary XML file line #257
12-21 18:46:37.166 D/PackageManager(  121): Scanning package com.myapp

2条回答
萌系小妹纸
2楼-- · 2019-07-19 05:15

Another way to get this exception and message is to misspell the name in the metadata in your manifest. For instance:

<meta-data
            android:name="android.cccontent.SyncAdapter"
            android:resource="@xml/syncadapter" />

Where it should be:

<meta-data
            android:name="android.content.SyncAdapter"
            android:resource="@xml/syncadapter" />

Hence the "No android.content.SyncAdapter meta-data" because it had "android.cccontent.SyncAdapter" instead. A more subtle example would be "android:content.SyncAdapter". Both of these will throw the exception:

org.xmlpull.v1.XmlPullParserException: No android.content.SyncAdapter meta-data
查看更多
该账号已被封号
3楼-- · 2019-07-19 05:31

I found it! Sure enough, that start-up message was key to finding the error. I had a mistake in my manifest. I put the meta-data nodes inside the intent-filter of the sync adapter. Therefore, my meta-data was hidden inside the intent-filter. Needless to say, the service could not be registered.

I am now on to my next bug :)

I hope this session is useful to others.

查看更多
登录 后发表回答