Reputation: 323
HI here is a small code i picked it from the sample code of google analytics.
tracker = GoogleAnalyticsTracker.getInstance();
tracker.startNewSession("UA-YOUR-ACCOUNT-HERE", this);
setContentView(R.layout.main);
Button createEventButton = (Button)findViewById(R.id.NewEventButton);
createEventButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
tracker.trackEvent(
"Clicks", // Category
"Button", // Action
"clicked", // Label
77); // Value
}
});
Error:
'05-14 13:52:36.599: E/AndroidRuntime(7367): FATAL EXCEPTION: main
05-14 13:52:36.599: E/AndroidRuntime(7367): java.lang.NoClassDefFoundError: com.google.android.apps.analytics.GoogleAnalyticsTracker
05-14 13:52:36.599: E/AndroidRuntime(7367): at com.google.android.apps.analytics.sample.TestActivity.onCreate(TestActivity.java:19)
05-14 13:52:36.599: E/AndroidRuntime(7367): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-14 13:52:36.599: E/AndroidRuntime(7367): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
05-14 13:52:36.599: E/AndroidRuntime(7367): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-14 13:52:36.599: E/AndroidRuntime(7367): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-14 13:52:36.599: E/AndroidRuntime(7367): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-14 13:52:36.599: E/AndroidRuntime(7367): at android.os.Handler.dispatchMessage(Handler.java:99)
05-14 13:52:36.599: E/AndroidRuntime(7367): at android.os.Looper.loop(Looper.java:130)
05-14 13:52:36.599: E/AndroidRuntime(7367): at android.app.ActivityThread.main(ActivityThread.java:3687)
05-14 13:52:36.599: E/AndroidRuntime(7367): at java.lang.reflect.Method.invokeNative(Native Method)
05-14 13:52:36.599: E/AndroidRuntime(7367): at java.lang.reflect.Method.invoke(Method.java:507)
05-14 13:52:36.599: E/AndroidRuntime(7367): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-14 13:52:36.599: E/AndroidRuntime(7367): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-14 13:52:36.599: E/AndroidRuntime(7367): at dalvik.system.NativeStart.main(Native Method)
Upvotes: 5
Views: 6298
Reputation: 3477
To solve the problem with the error NoClassdefFoundError when you are using the Google Analytics v2beta library, you need to mark this library as "exported".
How?
Your proyect will now find the Analytics class when you run it!
More details and why this happen here
Upvotes: 28
Reputation: 3937
I had this problem after updating ADT.
I was storing all of my JAR files in a folder called "lib" and adding the jars to the build path the normal Eclipse way. This worked fine until my update.
After my update, I was getting the NoClassDefFoundError for a class that I could clearly see was included in the jar (checking out the ReferencedLibraries classes).
The solution was to remove my jars from the build path and rename my "lib" folder to "libs". This is an ant convention, and seems to be the way the new ADT finds and includes libraries in an .apk file. Once I did this, everything worked fine.
Upvotes: 13