我的应用类
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):FATAL EXCEPTION:main 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,根据亚行经理,我正在尝试在Android 5.0 - API 21中实现。
此外,我已经将谷歌播放服务作为我的项目中的lib
您需要将Google Play服务链接为图书馆项目。
您可以在official site上阅读有关图书馆项目的更多信息。简而言之 - 当其他项目不仅包括源代码,还包括资源(布局,字符串)时,您需要使用库项目。
如果您需要使用仅包含源代码的库,您只需将.jar文件复制到libs
文件夹即可。
Google Analytics for Android的当前版本(v4)包含在Google Play服务项目中,其中包含资源,因此必须将其作为库项目引用。
例如,Google Analytics for Android的先前版本(v3)未包含在Google Play服务项目中,而且是一个简单的.jar库。