Android studio cannot resolve symbol common, missing from android.gms package - java

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.

Related

Android project which was working fine yesterday is now giving errors

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

Android studio - no option to import classes

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.

Setting up android studio with external libraries

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

The import com.badlogic cannot be resolved in Java Project Libgdx Setup

I've just tried to setup Libgdx to start making games, i followed this tutorial https://www.youtube.com/watch?v=S9fs1PVTyUc&feature=youtu.be
in conjunction with the libgdx grdale setup. However an error shows up in the Java project which says:
The import com.badlogic cannot be resolved
I am using Eclipse for Java IDE. I believe I have the Android SDK installed. I think it may be to do with the setup but i think the latest updates are there and i tried deleting '.m2'ccahe, which is not there any more btw after i deleted it (not been replaced), but this didnt work. Any ideas?
heres my code for the java proect:
import com.badlogic.gmx.Game;
public class GameMain extends Game{
}//'com.badlogic 'gets an error and so does 'Game'
The issue you are encountering is your eclipse project "CreateGame" is not setup correctly. It is missing the files needed to use libgdx.
Possible Solutions:
Use the libgdx project setup tool and then follow the instructions here to import the project to eclipse. (easy)
Add the missing library files to the project (hard)
Also make sure your game code is going into the game-core project as this project is used by each platform you are targeting.

Cannot resolve symbols yet library is imported

I'm using libGDX and I've cloned a project down from a repo I pushed too earlier. I've set the project up and imported it to Intellij IDEA but it's giving me import errors. I can actually navigate to the classes that are giving me an error but the IDE doesn't seem to recognise them.
How can I fix this?
When you hover over the unused import Intellij IDEA pops up a little red bulb which allows you to add the library to the classpath. Finding that fixed it.

Categories