I previously had this issue but after this issue was resolved a new issue started coming up.
The imports are showing error Cannot resolve the symbol x.
For ex All the below are showing error.
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.LinearLayout;
I have tested this on two project and for both the projects it is showing error. Any help would be grateful.
Sometimes Android Studio messes up the R.java and the indexes. And, only way to correct it is Gradle sync.
Restart, Clean and Rebuild the project.
Try to sync your project and rebuild. If that doesn't solve the issue try
File > Invalidate Caches > Invalidate and Restart.
If your problem is still not fixed, and you get and SDK error on trying to run your project, move your project directory to some place else and open it again in Android Studio.
Tried all the solution present in the web and other Stack overflow posts but non of them worked.
Finally I had to reinstall the Android Studio which solved the issue for me.
Related
Android Studio v3.2.1, SDK 28
All worked fine yesterday but then the layout previews stopped working (saying layout_width and layout_height) undefined. Eventually reinstalling fixed that but now I've getting problems with some imports not being recognized (android.view.View, java.util.List, android.app.Activity) but most are still OK (android.view.Display, java.util.Map etc.)
Also saying it can't find the Default Activity now although manifest is unchanged and MAIN/LAUCHER are present
Tried invalidating the cache and restarting, reinstalling studio, resyncing with gradle, reinstalling APK, cleaning project but error persists. I do remember updating the android emulator around the time the errors started but not sure why this would affect the editor.
Image:
import android.view.Display;
import android.view.View; // This line 'View' is a red error
import android.view.animation.Animation;
Oddly enough, it compiles successfully but won't launch.
EDIT: I tried changing the gradle version which did nothing so I changed it back and now it's launching again... Pulling my hair out on this one :/
EDIT: An older project which hasn't been upgraded doesn't have the same errors. I created a new project with one blank Activity which did have the same errors when I tried to add a few imports.
EDIT: I've deleted my SDK folder completely and done a completely fresh install. but still getting the same errors. Is it possible these classes have been deprecated?
EDIT (Temporary Solution) Changed the gradle settings to target SDK 27 and all of the errors have cleared. Hope I don't need a major code rewrite to move up to 28
Wow, I have used to get the same errors. The problem is that Android Studio recognized the file as a correct file, but overnight, Android Studio might detect errors. Try to re-write your file. If that does not work, think about what you had done before you experienced the error. Sometimes when you change files, it overrides another file, therefore resulting in a error.
When moving to API 28, did you try to convert to androidx?
Other things you can try:
Close Android Studio
Go to c:\users\~yourname~\.gradle and delete the caches folder entirely
Also delete the build folder in your app directory of your project
Start Android Studio
Rebuild your project
Hope this helps, cheers
I can not get any android classes to autofill in android studio. All of the android classes appear red ('cannot resolve symbol/method') and there is also no option for me to import class. If I manually enter the code to import the individual classes and compile my code it will run fine, however this is really annoying.
I have tried to 'Invalidate caches/restart'as suggested in other posts but this does not fix my issue. I have also checked updated everything in the android sdk as well as tried reinstalling android studio but nothing has worked.
Thanks for your help.
Trying to create a android junit ui test.
I've installed on my mac android studio, from project structure added Library Dependency of junit4, then added Module Dependency of android and uiautomator.
Gradle took care of setting up dependencies.
I went ahead to ApplicationTest class, and added import clauses for junit ui automation:
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiScrollable;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
but I get an error Cannot resolve symbol 'UiObject'. It can't find these packages
What am I doing wrong?
I encountered the same issue.
Firstly, please make sure you are using new call tree
import android.support.test.uiautomator.UiObject
If you still face this issue, then try:
File > Invalidate cache / restart should resolve this issue
I'm making a game where I'm using Google Play Services. I recently switched from eclipse to Android Studio (now running 0.8.14). In android studio I added a "Google Play Services Activity" and had my game class extend that class. I left the services class without modification. The project compiles and runs just fine but the IDE is filled with errors because it "cannot resolve symbol 'common'" and "cannot resolve symbol 'games'"
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.games.Games;
Any ideas on why this is and how to fix it?
I have attempted to reimport my project after deleting all .iml files and the .idea folder without result.
[EDIT]
As per request I'm adding a screenshot of the errors:
[EDIT 2]
I've kept searching for solutions and while I have not found any, I now have a screenshot that may be a bit more helpful.
As you can see, the com.google.android.gms package seems to be missing the common and games package.
I have tried updated gradle, tried using JDK 1.7 instead of 1.8 and attempted syncing with gradle multiple times. I will keep searching for an answer but if you have experienced this before, please feel free to help me and others out.
Add this to your build.gradle
dependencies {
compile 'com.google.android.gms:play-services:5.0.89'
}
Finally I found the real problem. Apparantly, my project was contained in a folder that ended with an exclamation mark. (myProjectName!) This caused Android studio to fail in finding certain imports.
Solution: I renamed my project from myProjectName! to myProjectName and moved the whole project to a new folder without the trailing exclamation mark. This seems to have fixed everything.
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
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
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.
right click on project->properties->android->select target name as "Android 4.4.2" --click ok
since DocumentsContract is added in API level 19
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.
try this in eclipse: Window - Preferences - Android - SDK Location and setup SDK path
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
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 this answer from here
Thanks .
RightClick on the Project > Properties > Android > Fix project properties
This solved it for me. easy.
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.