Reputation: 4271
I noticed that my google analytics ecommerce data are not properly delivered by my android app, while all the other analytics data (screen views, exceptions) are correctly published.
I already opened a bounty about this topic but digging further I discovered some errors in the logcat:
Error getting advertiser id: java.io.IOException: java.util.concurrent.TimeoutException: Timed out waiting for the service connection
Successfully bound to service but never got onServiceConnected callback
I suspect these errors are due to something not working at play-services level, that's why I'm opening a new thread.
Since the above errors appear in logs before hits are delivered my theory is that my ecommerce data are not correctly posted because of them. Did anybody here ever see anything like that? What could I try in order to fix it?
Please notice I'm using (taken from build.gradle)
compile 'com.google.android.gms:play-services-analytics:9.4.0'
compile 'com.google.android.gms:play-services-ads:9.4.0'
apply plugin: 'com.google.gms.google-services'
and the gradle plugin
classpath 'com.android.tools.build:gradle:2.2.0-beta1'
Upvotes: 13
Views: 7381
Reputation: 105
From my latest tests it seems that onServiceConnected
is not called when trying to get an android id from the main thread. It can lead to deadlocks (as in @DimPar case) and to timeout exceptions, when you try to prevent a deadlock with a timeout on a Thread.join
.
It seems that android doesn't allow external SDK to create separate threads (even when they directly do that by creating a new Thread and starting it).
In other words - if you use an sdk that tries to get the android id even if it should work - it won't. The solution to this would call all the external SDK functions on separate thread that you create in the activity.
Here is an example from my personal experience.
The following code block deadlocks:
public class MainActivity extends AppCompatActivity {
static boolean doOnce = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if( doOnce ) {
ExternalSDKClass.StartInitialization();
doOnce = false;
}
}
The following code block works
public class MainActivity extends AppCompatActivity {
Thread ExternalSDKThread = new Thread() {
@Override
public void run() {
try {
ExternalSDKClass.StartInitialization();
} catch (Exception e) {
Log.i("SDK ERROR", "getAdvertisingIdInfo Exception: " + e.toString());
}
}
};
//---------------------------------
static boolean doOnce = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if( doOnce ) {
ExternalSDKThread.start();
doOnce = false;
}
}
Upvotes: 0
Reputation: 159
I had the following error
java.util.concurrent.TimeoutException: Timed out waiting for the service connection
The error has been fixed after the caller method was moved to the non-main thread. I'm not sure this solution will help you but you can check it out.
Upvotes: 0
Reputation: 19250
In my case another error (A Virtual method not found
error) was holding this and causing this to timeout. After resolving it, Ad id was successfully retrieved.
Upvotes: 0
Reputation: 363
I fixed this error by adding this to dependencies
block in gradle.build
file:
implementation 'com.google.android.gms:play-services-base:16.0.1'
Upvotes: 1