Search code examples
androidgoogle-apim2eclipse

AndroidRuntime: The import com.google.api.client cannot be resolved


Has anybody else seen this problem where imports can't be resolved at Andriod runtime?

I am trying to build the calendar android sample by following the instructions: http://samples.google-api-java-client.googlecode.com/hg/calendar-android-sample/instructions.html?r=default

My build path contains the following:

BuildPath

It builds OK in Eclipse with no problems/warnings. However when I launch it on my HTC (android 2.3.3) but it "stops unexpectedly" and in LogCat it says:

E/AndroidRuntime(8170): java.lang.Error: Unresolved compilation problems: 
E/AndroidRuntime(8170):     The import com.google.api.client cannot be resolved
Followed by many other google-api import resolution failures.

And when run under debug: the code window shows it stopping at the first import

package com.google.api.services.samples.calendar.android;
import com.google.api.client.extensions.android2.AndroidHttp; << stops here

I'm not sure if the import failures are specific to the google API stuff or a more widespread issue with imports.

I guess that somehow Maven is not linking these libraries into the APK. It surprises me that this issue does not get flagged as a problem at build time where I might have better luck in fixing them.

I suspect I have damaged my Maven installation somehow and possibly even Eclipse also. My next step is to wipe them completely and start with fresh installs.

Has anybody seen this problem where imports can't be resolved at runtime? Or maybe someone has some advice on areas of investigation that I might pursue? Or any relevant experiences that you have would be welcome.

Kind Regards, Peter


Solution

  • In addition to upgrading to Java 6, I would suggest removing all external libraries and re-adding them. Eclipse generally has major problems when you upgrade Java or ADT versions (in my case anyway), and the best solution for me has been to wipe everything out and start over.

    If removing all dependencies/external libraries and re-adding them doesn't solve your problem I suggest creating a new project, copying over all your assets, then re-adding the google libraries there.