简体   繁体   中英

Android StringIndexOutOfBoundsException inside Google Analytics SDK

Recently, my app got some crash reports with that exception:

0  java.lang.StringIndexOutOfBoundsException: length=8; regionStart=0; regionLength=32
1   at java.lang.String.startEndAndLength(String.java:593)
2   at java.lang.String.substring(String.java:1474)
3   at com.google.ads.util.AdUtil.b(SourceFile:447)
4   at com.google.ads.AdRequest.<clinit>(SourceFile:210)
5   at java.lang.Class.classForName(Native Method)
6   at java.lang.Class.forName(Class.java:217)
7   at java.lang.Class.forName(Class.java:172)
8   at com.google.analytics.tracking.android.AdHitIdGenerator.<init>(AdHitIdGenerator.java:17)
9   at com.google.analytics.tracking.android.GoogleAnalytics.<init>(GoogleAnalytics.java:65)
10  at com.google.analytics.tracking.android.GoogleAnalytics.<init>(GoogleAnalytics.java:56)
11  at com.google.analytics.tracking.android.GoogleAnalytics.getInstance(GoogleAnalytics.java:92)
12  at com.buscaalimento.android.proxies.GoogleAnalyticsProxy.<init>(GoogleAnalyticsProxy.java:26)
13  at com.buscaalimento.android.proxies.GoogleAnalyticsProxy.createInstance(GoogleAnalyticsProxy.java:40)

Apparently, it seens to be an error inside the Google Analytics SDK jar. I've use the JD-GUI tool to see the code inside the jar. The line who triggers the exception seems like:

AdHitIdGenerator.java:

try
{
  this.mAdMobSdkInstalled = (Class.forName("com.google.ads.AdRequest") != null);
} catch (ClassNotFoundException e) {
  this.mAdMobSdkInstalled = false;
}

The code (my code) who calls the GoogleAnalytics class is this:

public GoogleAnalyticsProxy(Context context) {
    GoogleAnalytics gaInstance = GoogleAnalytics.getInstance(context);
    if (DietaeSaudeApplication.isDebugging() || FORCE_DEBUG) {
        MvLog.d(this, "Running in debug mode!!");
        mTracker = gaInstance.getTracker(DEBUG_TRACKING_ID);
        gaInstance.setDebug(true);
    } else {
        MvLog.d(this, "Running in release mode!!");
        mTracker = gaInstance.getTracker(RELEASE_TRACKING_ID);
        gaInstance.setDebug(false);
    }
    GAServiceManager.getInstance().setDispatchPeriod(30); //dispatch a cada 30 segundos
}

The exception occurs in this line:

GoogleAnalytics gaInstance = GoogleAnalytics.getInstance(context);

This code is called inside the Application class, where i create the singletons of my app. I really dont have a clue about this error. Anyone has passed by this issue?

Pedro,

It seems you're getting the error from another SDK class.

According to the stacktrace, at line 4, the SDK package name changes from com.google.analytics.tracking.android to com.google.ads . This means it found the "AdRequest" class from the Google Mobile Ads SDK ads package but somehow it threw an exception.

You could try updating all the SDKs to their last version. Or, in the worst scenario, use an old SDK version for the Ads while a fix is not released.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM