32

My android application, built inside Eclipse, suddenly fails to build with dozens of errors. The most obvious are errors indicating that all the android imports cannot be resolved.

import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

All of these are flagged as unresolvable. I've tried removing and re-adding the JRE System Library. I've tried cleaning and rebuilding. I've tried the "Quick fix" option to "Fix Project Setup..." but that simply responds with a dialog box that say...

"No proposals have been found to fix the unresolvable reference to 'android.app.Bundle'. Click here to manually configure the build path of project 'Silent Mode Toggle."

I'm new to Android development and this one has me completely stumped.

Thanks in advance for any help you can provide.

Rich

mattbasta
  • 13,492
  • 9
  • 47
  • 68
Rich Wooley
  • 375
  • 1
  • 3
  • 9
  • 2
    somehow your Android SDK got removed or corrupted. Check `Window->preferences->Android` and see if the SDK path listed at the top still correctly points to a valid SDK installation. – FoamyGuy Jul 20 '12 at 17:58
  • 1
    The SDK doesn't even need to get removed or corrupted, Eclipse may simply not be pointed at it in this instance. That can easily happen if you make a new workspace, import a project, etc. – Chris Stratton Jul 20 '12 at 18:00
  • @ChrisStratton my mistake the SDK itself is not necessarily removed or corrupted, it could be the path to it that eclipse stores. – FoamyGuy Jul 20 '12 at 18:02
  • You shouldn't be adding System JRE: instead, you need to add Android library, which internally will include the JRE. See here: http://imageshack.us/photo/my-images/688/screenshot20120720at190.png/ – Aleks G Jul 20 '12 at 18:04
  • @AleksG mention of system JRE makes me wonder if this was created as a generic Java project rather than as an Android project – Chris Stratton Jul 20 '12 at 18:12
  • @ChrisStratton Possibly, but I understood from the question that it did build before and now it doesn't. – Aleks G Jul 20 '12 at 18:42
  • This project was created as an Android project, not a Java project. It was a sample program from a book and was built originally as an application, then it was converted to a widget. That's when things went wrong. The app was small, so I re-created the project and it now builds fine. – Rich Wooley Jul 25 '12 at 14:02

9 Answers9

27

It seems that your eclipse-workspace (or at least your Project) is broken somehow.

Have you moved your android-sdk/Project recently? If it's not an Android Project anymore, try to look at Preferences->Android for a valid android sdk-location.

If this is correct, try to open a complete new Workspace, and import your sources with File->import->Android Project from existing Source.

If this still doesn't help, make a new android Project and copy the sources manually inside your Project from outside Eclipse. Re-open Eclipse after that, and make a Project->clean

SaiyanGirl
  • 16,376
  • 11
  • 41
  • 57
Rafael T
  • 15,401
  • 15
  • 83
  • 144
16

What all the others said.

Specifically, I recommend you go to Project > Properties > Java Build Path > Libraries and make sure you have exactly one copy of android.jar referenced. (Sometimes you can get two if you're importing a project.) And that its path is correct.

Sometimes you can get the system to resolve this for you by clicking a different target SDK in Project > Properties > Android, then restoring your original selection.

Pacerier
  • 86,231
  • 106
  • 366
  • 634
Sparky
  • 8,437
  • 1
  • 29
  • 41
9

right click on project->properties->android->select target name as "Android 4.4.2" --click ok

since DocumentsContract is added in API level 19

Angad Tiwari
  • 1,738
  • 1
  • 12
  • 23
5

I just had the same problem after accepting a Java update--scores of build errors and android import not recognized. On checking the build path in Project=>Properties, I found that the check box for Android 4.3 had somehow gotten cleared. Checking it resolved all the import errors without my even having to restart the IDE or run a project clean.

user382459
  • 141
  • 2
  • 3
  • I believe that this is the correct way to go (especially if you dont want to create a new workspace or project) – netcyrax Dec 23 '13 at 05:40
1

try this in eclipse: Window - Preferences - Android - SDK Location and setup SDK path

K_Anas
  • 31,226
  • 9
  • 68
  • 81
  • I created a new project and this problem went away. I suspect the suggestion of a corrupted reference to the SDK was correct. – Rich Wooley Jul 24 '12 at 18:04
  • @RichWooley you can mark the answer as accepted, to tell others that this question was solved!! This is how to accept answer http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – K_Anas Jul 25 '12 at 00:19
1

This import android packages cannot be resolved is also occurs when your using some library and that library is not in the same path where your application is there, or if you are importing the library and not coping library to the workspace

W I Z A R D
  • 1,224
  • 3
  • 17
  • 44
1

May be you are using this checking :

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
}

To resolve this you need to import android.provider.DocumentsContract class.

To resolve this issue you'll need to set the build SDK version to 19 (4.4) or higher to have API level 19 symbols available while compiling.

First, use the SDK Manager to download API 19 if you don't have it yet. Then, configure your project to use API 19:

  • In Android Studio: File -> Project Structure -> General Settings -> Project SDK.
  • In Eclipse ADT: Project Properties -> Android -> Project Build Target

I found the answer quoted above here, by laalto

blackgreen
  • 34,072
  • 23
  • 111
  • 129
Md. Sajedul Karim
  • 6,749
  • 3
  • 61
  • 87
1
RightClick on the Project > Properties > Android > Fix project properties

This solved it for me. easy.

kc ochibili
  • 3,103
  • 2
  • 25
  • 25
0

To import android packages, ADT plugin of eclipse is required, only after this you can add it in the java build path.

Go to your eclipse market and download the Android AD extension.

Amit Rai
  • 289
  • 1
  • 4
  • 22