我的应用类
public class MyApplication extends Application {
private static final String PROPERTY_ID = "UA-XXXXXX-X";
public static int GENERAL_TRACKER = 0;
public enum TrackerName {
APP_TRACKER, // Tracker used only in this app.
GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg:
// roll-up tracking.
ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a
// company.
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
public MyApplication() {
super();
}
public synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
analytics.getLogger().setLogLevel(Logger.LogLevel.VERBOSE);
Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics
.newTracker(PROPERTY_ID)
: (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics
.newTracker(R.xml.global_tracker) : analytics
.newTracker(R.xml.ecommerce_tracker);
mTrackers.put(trackerId, t);
}
return mTrackers.get(trackerId);
}
}
app_tracker.xml
<string name="ga_trackingId">UA-XXXXXX-X</string>
<string name="ga_sampleFrequency">100</string>
<bool name="ga_autoActivityTracking">true</bool>
<bool name="ga_reportUncaughtExceptions">true</bool>
<integer name="ga_sessionTimeout">-1</integer>
<screenName name="com.mobihouse.portabilidade.activities.HomeActivity_">HomeActivity</screenName>
global_tracker.xml
<integer name="ga_sessionTimeout">300</integer>
<!-- Enable automatic Activity measurement -->
<bool name="ga_autoActivityTracking">true</bool>
<string name="ga_logLevel">verbose</string>
<!-- The screen names that will appear in reports -->
<screenName name="com.mobihouse.portabilidade.activities.HomeActivity_">HomeActivity Portabilidade</screenName>
<!-- The following value should be replaced with correct property id. -->
<string name="ga_trackingId">UA-XXXXXX-X</string>
在我的清单中,我已经添加了这个:
<application
android:name="com.mobihouse.portabilidade.MyApplication"
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.gms.analytics.globalConfigResource"
android:resource="@xml/global_tracker" />
我将我的 PROPERTY_ID 更改为在此处发布。
问题是,记录:
11-25 09:23:30.031:E/AndroidRuntime(8392):致命异常:主要 11-25 09:23:30.031:E/AndroidRuntime(8392):java.lang.NoClassDefFoundError:com.google.android.gms。 analytics.GoogleAnalytics 11-25 09:23:30.031: E/AndroidRuntime(8392): at com.mobihouse.portabilidade.MyApplication.getTracker(MyApplication.java:45)
和:
11-25 09:23:29.992: I/dalvikvm(8392): 找不到方法 com.google.android.gms.analytics.Tracker.setScreenName,引用自方法 com.mobihouse.portabilidade.activities.HomeActivity.onCreate
11-25 09:23:29.992: I/dalvikvm(8392): 找不到方法 com.google.android.gms.analytics.GoogleAnalytics.getInstance,引用自方法 com.mobihouse.portabilidade.activities.HomeActivity.onStart
我搜索了几个站点,但是所有解决方案都不起作用,有人可以帮助我吗?
我已经更新了谷歌播放服务库,我的当前版本 = 21,根据 ADB Manager,我正在尝试在 Android 5.0 - API 21 中实现。
此外,我已经将 google play 服务作为库放在我的项目中