Setting up android studio with external libraries - java

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

Related

The import jdk.nashorn cannot be resolved

I am trying to import a project into my eclipse workspace. When I maven updated the project, this dependency is not getting downloaded.
When I searched online, I found that jdk.nashorn is not supported from java 11 onwards. But I am using java 1.8.0_231, still its not working for me.
The code uses below class from the library.
import jdk.nashorn.internal.ir.debug.ObjectSizeCalculator;
ObjectSizeCalculator.getObjectSize(modRespList)
Is there any way to make this code work?

Android Studio Showing imports error

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.

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

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.

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.

import android packages cannot be resolved

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.

Categories