0

我Aplication類gms.analytics.GoogleAnalytics - NoClassDefFoundError的

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): Could not find method com.google.android.gms.analytics.Tracker.setScreenName, referenced from method com.mobihouse.portabilidade.activities.HomeActivity.onCreate

11-25 09:23:29.992: I/dalvikvm(8392): Could not find method com.google.android.gms.analytics.GoogleAnalytics.getInstance, referenced from method com.mobihouse.portabilidade.activities.HomeActivity.onStart

我搜索了幾個網站,但所有的解決方案沒有奏效,有人可以幫助我嗎?

我已經更新了谷歌播放服務的lib,我目前的版本= 21,根據亞行的經理,我想在安卓5.0來實現 - API 21

而且我已經把谷歌Play服務,因爲一個lib在我的項目中

+0

具有u加入Google分析JAR文件庫folder..and在構建路徑 – Meenal 2014-11-25 11:46:33

+0

@Meenal夏爾馬,我沒有信譽把圖像中加入它,所以我上傳我的庫的圖像: HTTP:// postimg 。org/image/xw6ddrq6z/ http://postimg.org/image/qnbo6x0qh/ 請看看plz。謝謝。 – 2014-11-25 12:18:29

+0

也許您需要鏈接到Google Play服務作爲圖書館項目? – 2014-11-25 14:58:19

回答

0

您需要將Google Play服務作爲庫項目鏈接。

您可以在official site上閱讀更多關於庫項目的信息。 不久 - 您需要使用庫項目,當其他項目不僅包括源代碼,但資源(佈局,字符串)。

如果您需要使用僅包含源代碼的庫,則可以簡單地將.jar文件複製到libs文件夾中。

Google Analytics for Android的當前版本(v4)包含在Google Play Services項目中,該項目包含資源,因此必須將其引用爲庫項目。

例如,Google Analytics for Android的以前版本(v3)未包含在Google Play服務項目中,並且是一個簡單的.jar庫。