Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync not working on Android API level 15 (4.0.3) #165

Closed
kasim1011 opened this issue May 17, 2016 · 9 comments
Closed

Sync not working on Android API level 15 (4.0.3) #165

kasim1011 opened this issue May 17, 2016 · 9 comments
Labels

Comments

@kasim1011
Copy link
Contributor

I've prepare demo for performing sync operation here. which works perfectly on Android Emulator (Android 6.0) as well as my device Moto E XT1022 (Android 5.0.2) but, it doesn't work on Sony Tablet S (Android 4.0.3). It gets force stop with following errors. Any kind of help or suggestions will be appreciated. Thanks in advanced.

E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method com.odoo.App.access$super
E/dalvikvm: Could not find class 'android.app.Application$OnProvideAssistDataListener', referenced from method com.odoo.App.access$super
E/dalvikvm: Could not find class 'android.app.Application$OnProvideAssistDataListener', referenced from method com.odoo.App.access$super
E/dalvikvm: Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.monkeyPatchExistingResources
E/dalvikvm: Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.pruneResourceCache
E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method com.odoo.addons.partners.services.PartnersSyncService.access$super
E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method com.odoo.core.service.OSyncService.access$super
E/dalvikvm: Could not find class 'android.os.CancellationSignal', referenced from method com.odoo.addons.partners.providers.PartnersSyncProvider.access$super
E/dalvikvm: Could not find class 'android.os.CancellationSignal', referenced from method com.odoo.core.orm.provider.BaseModelProvider.access$super


E/AndroidRuntime: FATAL EXCEPTION: SyncAdapterThread-1
                  java.lang.ExceptionInInitializerError
                      at android.content.ContentProvider.attachInfo(ContentProvider.java:929)
                      at android.app.ActivityThread.installProvider(ActivityThread.java:4260)
                      at android.app.ActivityThread.acquireProvider(ActivityThread.java:4058)
                      at android.app.ContextImpl$ApplicationContentResolver.acquireProvider(ContextImpl.java:1618)
                      at android.content.ContentResolver.acquireProvider(ContentResolver.java:949)
                      at android.content.ContentResolver.acquireContentProviderClient(ContentResolver.java:984)
                      at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:245)
                   Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
                      at android.os.Handler.<init>(Handler.java:121)
                      at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:607)
                      at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:607)
                      at android.os.AsyncTask.<clinit>(AsyncTask.java:190)
                      at android.content.ContentProvider.attachInfo(ContentProvider.java:929) 
                      at android.app.ActivityThread.installProvider(ActivityThread.java:4260) 
                      at android.app.ActivityThread.acquireProvider(ActivityThread.java:4058) 
                      at android.app.ContextImpl$ApplicationContentResolver.acquireProvider(ContextImpl.java:1618) 
                      at android.content.ContentResolver.acquireProvider(ContentResolver.java:949) 
                      at android.content.ContentResolver.acquireContentProviderClient(ContentResolver.java:984) 
                      at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:245)
@kasim1011 kasim1011 changed the title Sync not working on Android API 15 (4.0.3) Sync not working on Android API level 15 (4.0.3) May 17, 2016
@kasim1011
Copy link
Contributor Author

kasim1011 commented May 17, 2016

I had some research regarding above errors on Internet and I've got following.

Above all comes together in one framework which has minSdkVersion 14. how this thing is possible?

@kasim1011
Copy link
Contributor Author

I've tried android-odoo-contacts-2016 to find out whether sync is working or not. but, it's working fine on Android 4.0.3 than why framework gives error on sync.

@dpr-odoo Please, fix this bug ASAP.
@74n3r
@merajuddin1
@warp10
@YPerezM

@YPerezM
Copy link

YPerezM commented Jun 2, 2016

I am learning by myself so do not know if it is irrelevant, but in my app I could not sync from device to server (sync only worked from server to device). It is rare because it was working fine the sync all the time for me, but I found that the problem is that I add some new OColumns that does not let me sync correctly.

So, in my case, the sync does not work because of a few new columns in the database.

@kasim1011
Copy link
Contributor Author

@YPerezM Thanks for the update.

@Tanererkan06
Copy link

@YPerezM @kasim1011 auto sync still doesn't work :/

@dpr-odoo dpr-odoo added the bug label Nov 15, 2016
@dpr-odoo
Copy link
Collaborator

@kasim1011 can you check it with latest update?

@kasim1011
Copy link
Contributor Author

@dpr-odoo
@r-mckay
@mikedream89

Let's take on model standard.standard.
At the time of opening the issue. The code was like

package com.abc.xyz.addons.employees.models;

public class StandardStandard extends OModel {

    public static final String TAG = StandardStandard.class.getSimpleName();
    public static final String AUTHORITY = "com.abc.xyz.addons.employees.standard_standard";

    OColumn sequence = new OColumn("Sequence", OInteger.class);
    OColumn name = new OColumn("Name", OVarchar.class);
    OColumn code = new OColumn("Code", OVarchar.class);

    public StandardStandard(Context context, OUser user) {
        super(context, "standard.standard", user);
    }

    @Override
    public Uri uri() {
        return buildURI(AUTHORITY);
    }
}

After solving the Issue the code was look like.

package com.abc.xyz.addons.employees.models;

public class StandardStandard extends OModel {

    public static final String TAG = StandardStandard.class.getSimpleName();
    public static final String AUTHORITY = "com.abc.xyz.addons.employees.models.standard_standard";

    OColumn sequence = new OColumn("Sequence", OInteger.class);
    OColumn name = new OColumn("Name", OVarchar.class);
    OColumn code = new OColumn("Code", OVarchar.class);

    public StandardStandard(Context context, OUser user) {
        super(context, "standard.standard", user);
    }

    @Override
    public Uri uri() {
        return buildURI(AUTHORITY);
    }
}

Now, in 2nd code snippet the AUTHORITY is exactly same as package name. This prevents force stops in various devices. I want to add another working snippet

public class ResPartner extends OModel {
    public static final String AUTHORITY = BuildConfig.APPLICATION_ID +
            ".core.provider.content.sync.res_partner";
}

So, Both 2nd & 3rd is working. This thing makes me confuse which snippet to use for better practice. We want some words from @dpr-odoo on this?

@dpr-odoo
Copy link
Collaborator

When dealing with Sync Service you need to take care of following things:

For sync service with sync adapter you need four components:

  1. Service https://github.com/Odoo-mobile/framework/blob/master/app/src/main/java/com/odoo/addons/customers/services/CustomerSyncService.java
  2. Content Provider https://github.com/Odoo-mobile/framework/blob/master/app/src/main/java/com/odoo/addons/customers/providers/CustomersSyncProvider.java
  3. XML file (sync-adapter) https://github.com/Odoo-mobile/framework/blob/master/app/src/main/res/xml/customer_sync_adapter.xml
  4. Entry of service and provider in Manifest file https://github.com/Odoo-mobile/framework/blob/master/app/src/main/AndroidManifest.xml#L87-L104

In all these component AUTHORITY is commonly shared with each other that links each of the component together.

Also when user start sync from settings->account android will trigger sync-adapter that we have created in xml and linked with sync service which has AUTHORITY.

authority can by any valid string but for better practice, we create it starts with applicationId so we get unique authority.

If you are using custom authority, you have to pass it to sync_adapter.xml, ModelDataProvider and authority string to Manifest with Provider

Hope this will help to understand the working of sync service with sync-adapter and authority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants
@Tanererkan06 @dpr-odoo @kasim1011 @YPerezM and others