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