Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android google analytics tracker NoClassdefFoundError

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)
like image 573
Sukesh Avatar asked May 14 '12 08:05

Sukesh


2 Answers

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?

  • Add your library: Project -> Properties -> Java Build Path -> Libraries -> Add External JARs...
  • Then go to "Order and Export" in the same window, and mark this library as "exported" with the checkbox.

Your proyect will now find the Analytics class when you run it!

More details and why this happen here

like image 175
Pelanes Avatar answered Nov 15 '22 17:11

Pelanes


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.

like image 13
Jackson Chengalai Avatar answered Nov 15 '22 17:11

Jackson Chengalai