hello i am quite new to Android development and i want to learn how to use the google Maps API v2. After trying numerous tutorials, i always seem to have a problem with the google play services library. Somehow, Eclipse can't import it properly. I tried this tutorial https://github.com/thecodepath/android_guides/wiki/Google-Maps-Fragment-Guide and when i try to include Google Play Services project as a library, first it all goes nice and smooth, i get a green tick in the Project Properties - Android - Library window, but when i close it i still get lots of "can't be resolved to a type" errors. I return to the window where i add the library and i see a red "X" and a question mark under "project" instead of the green tick. I tried several other tutorials and i always have a problem with this library. I like this tutorial and i would really like to make it work. I also tried to manually copy the library folder in the workspace but that didn't work either. I googled like crazy trying to find an answer but i always find something that i tried before (like manually copying the library in the workspace or something similar). I am quite desperate, i really have no idea why it can't just see the library please help. Also this is my first post to StackOverflow so be gentle :)
later Edit (solved):
when i imported the downloaded project, i kept it on the desktop and thats why it didn't work, after i copied it in the workspace everything worked. Thank you all very much for helping a beginner :)
The important thing in adding a library in eclipse is to remember that your project and the library project need to be in the same workspace.
To solve this follow below ways,
You can copy the google-play-services library project to the same workspace where your main project is there.
else
While importing the library to eclipse remember to check copy projects into workspace which will add a copy of the library to your workspace.
I see a red "X" and a question mark under "project" instead of the
green tick.
The problem is -
The path to your google play services library is not same as the path to your project. It is outside of your project. And so is not recognized by simple import.
Solution - Put the library in the project's libs folder.
NOTE: Just putting the library to the libs folder is not enough.
After you added your library follow these steps -
1) Go to Project -> Properties -> Java Build Path -> Libraries -> Add JARs..
2) Now add your recently added jar to the build path from JAR selection process.
3) Go to Project -> Properties -> Java Build Path -> Order and Export.
4) Put a tick mark in the check box against this library name and press OK.
5) Do Project -> Clean.
if your giving google-Play-Service-lib as a references to your project , try to keep your project and the Google-play services lib should be in same drive.
if your project is on C: drive means place Google-play-services-lib in C:
While making the copy of the entire folder libproject containing google-play-services_lib from eclipse import project by selecting the copied libproject folder in your working place.
For the rest follow the steps in Setting Up Google Play Services
Eclipse
Copy the library project at
<android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/
to the location where you maintain your Android app projects.
Import the library project into your Eclipse workspace. Click
File > Import, select Android > Existing Android Code into Workspace
and browse to the copy of the library project to import it.
After you've added the Google Play services library as a dependency for your app project, open your app's manifest file and add the following tag as a child of the <application> element:
< meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Android Studio
Open the build.gradle file inside your application module directory.
Add a new build rule under dependencies for the latest version of play-services
eg
...
dependencies {
compile 'com.google.android.gms:play-services:9.2.0'
}
apply plugin: 'com.android.application'
Source developers.google.com
Related
Am trying to add google-play-service library in my project using import(For Google map). After adding the path am getting red X next to this reference and the reference is not adding . Know how to resolve this ?
The red X means its a broken link path.
http://developer.android.com/google/play-services/setup.html
Copy the google-play services_lib library project to your workspace (folder where your android map project is). The library project can be found under the following path.
<android-sdk-folder>/extras/google/google_play_services/libproject/google-play-services_lib library project .
Import the library project to your eclipse
Click File > Import, select Android > Existing Android Code into Workspace, and browse the workspace import the library project. You can check if it is library project. Right click on the library project. Goto properties. Click Android on the left panel. You will see Is Library checked.
Right click on your android project. Goto properties. Choose Android on the left panel. Click on Add and browse the library project. Select the same. Click ok and apply
Eclipse does weird things when importing an existing project (google-play-services-lib), especially if you try to import and then allow the project to be automatically 'copied' to your workspace. I had the same issue and here is how I fixed it:
Close Eclipse
Erase all google-play-services projects from your workspace
Manually copy the google-play-services-lib folder (....sdk\extras\google\google_play_services\libproject\google-play-services_lib) into your workspace
Open Eclipse
Add a new project, choosing 'Existing Android Project', then navigate to your workspace and add the newly copied google-play-services-lib project
Finally, add the google-play-services-lib to your project as a library (just like you normally would)
Hope this helps! :)
Though it's over a year for this question but never the less thought of putting it down here. Might help some one facing a similar issue.
While doing a File -> Import one probably might have selected the folder,
C:\adt-bundle-windows-x86-20130729\sdk\extras\google\google_play_services\
instead of
C:\adt-bundle-windows-x86-20130729\sdk\extras\google\google_play_services\libproject\google-play-services_lib
Quite strange as Eclipse did not correctly copy the google-play-services_lib project in my workspace, but this caused a cross mark to appear in my Project Properties.
got a perfect solution for your question. this problem is due to improper referencing of library projects. You need follow these step.
create a new project
copy all the java files from src of your previous project in which you are getting error to the new project you have created just now.
Also copy layouts xml files.
now import play services you will not get this error.
I was also getting same problem.
I copied google library folder into work space and import now it's working fine.
Try to place the Google-play-service library with in your same working Directory by coping the files from Click File > Import, select Android > Existing Android Code into Work space, and browse the work space import the library project.
This is common issue Youur google-play-service-lib project and your android project should be inside the same folder For example
if your Android Appplication name is MyMap is in D:/workspace t hen your play service lib project should be in the same directory D:/workspace
Close Eclipse. Delete
.metadata
and
.recommaditions
folders from your workplace. Import your projects back.
You add Project in to your workspace.
Start Eclipse and import project one option is ther copy to workspace do it.
After that add google play services it also copy in to your work space
and add it your library hope so its working.
I have an application that I have to look at as a training exercise. It has used few external libraries such as SlidingMenu, ImageViewZoom and ActionbarSherlock.
I have downloaded and extracted those libraries but I have no idea how to add them to my existing project.
For those that are distributed as a simple JAR, do what Emil Adz indicates, and copy that JAR into your project's libs/ directory.
For those, like ActionBarSherlock, that are distribute as Android library projects, you will need to do a bit more work. In the case of Eclipse, you will need to import the library project into your workspace, then go into Project > Properties > Android for your application project and click the [Add] button to add the library project to the application project. For a command-line build, use android update lib-project to link the application and library project together.
You can read more about referencing an Android library project from Eclipse or the command line in the documentation.
You need to import those libraries as Android Project from existing source and mark them as "Is Library" by going into their properties.
Once you marked it as "Is Library" add it to your
project by going into Properties->Android->Library->Add (it will show the list of library you imported).
The Right Way:
What you need to do is to copy the external library (JAR file) to the /libs folder of your project.
That way those libraries will compile with your project and could be use on real device when you deploy your application.
Some times you will need to add a project to your workspace ( For example the Google Map library)
and then add the library reference using the properites -> Android window at the bottom.
You can get an idea of how it's done by reading the first 3 step of this Google Map API V2 guide I wrote. there I reference the android library project:
Google Map API V2 Guide
The Wrong Way:
any other way, like for example adding the files using the properties - > Java build path screen may result in a missing library when you run the project on a real device.
if they are jars the make a libs folder then paste the jar in it and then go to your project buildpath->configure build path->Add Jars-> ok and if it is a library project then go to your project Property->Android->Add(Your Lib Project)->Ok->Apply
I have following problem:
I try to use SupportMapFragment from com.google.android.gms.maps.SupportMapFragment which is part of Google Maps Android API v2.
My first approach was to add project to Eclipse from android-sdk\extras\google\google_play_services\libproject\google-play-services_lib location and set it as referenced project in Properties -> Project References menu of MyApp. I also added project to Java Build Path / Projects. Error indicators disappeared from Eclipse but when I tried to run my app I got NoClassDefFoundError exception.
So my second approach was to copy jar file from google-play-services_lib/libs to my project's libs directory. MyApp succesfully started but in LogCat I can see dead code ... something message so I guess that jar file has to be referenced in another way.
And now I am confused and tired..
Maybe someone more experienced in Android can tell me what should I do ?
The quick start guide that keyboardsurfer references will work if you need to get your project to build properly, but it leaves you with a dummy google-play-services project in your Eclipse workspace, and it doesn't properly link Eclipse to the Google Play Services Javadocs.
Here's what I did instead:
Install the Google Play Services SDK using the instructions in the Android Maps V2 Quick Start referenced above, or the instructions to Setup Google Play Services SDK, but do not follow the instructions to add Google Play Services into your project.
Right click on the project in the Package Explorer, select Properties to open the properties for your project.
(Only if you already followed the instructions in the quick start guide!) Remove the dependency on the google-play-services project:
Click on the Android category and remove the reference to the google-play-services project.
Click on the Java Build Path category, then the Projects tab and remove the reference to the google-play-services project.
Click on the Java Build Path category, then the Libraries tab.
Click Add External JARs... and select the google-play-services.jar file. This should be in [Your ADT directory]\sdk\extras\google\google_play_services\libproject\google-play-services_lib\libs.
Click on the arrow next to the new google-play-services.jar entry, and select the Javadoc Location item.
Click Edit... and select the folder containing the Google Play Services Javadocs. This should be in [Your ADT directory]\sdk\extras\google\google_play_services\docs\reference.
Still in the Java Build Path category, click on the Order and Export tab. Check the box next to the google-play-services.jar entry.
Click OK to save your project properties.
Your project should now have access to the Google Play Services library, and the Javadocs should display properly in Eclipse.
What i have done is that import a new project into eclipse workspace, and that path of that was be
android-sdk-macosx/extras/google/google_play_services/libproject/google-play-services_lib
and add as library in your project.. that it .. simple!!
you might require to add support library in your project.
Be Careful, Follow these steps and save your time
Right Click on your Project Explorer.
Select New-> Project -> Android Application Project from Existing Code
Browse upto this path only - "C:\Users**your path**\Local\Android\android-sdk\extras\google\google_play_services"
Be careful brose only upto - google_play_services and not upto google_play_services_lib
And this way you are able to import the google play service lib.
Let me know if you have any queries regarding the same.
Thanks
Some of the solutions described here did not work for me. Others did, however they produced warnings on runtime and javadoc was still not linked. After some experimenting, I managed to solve this. The steps are:
Install the Google Play Services as recommended on Android Developers.
Set up your project as recommended on Android Developers.
If you followed 1. and 2., you should see two projects in your workspace: your project and google-play-services_lib project. Copy the docs folder which contains the javadoc from <android-sdk>/extras/google/google_play_services/ to libs folder of your project.
Copy google-play-services.jar from <android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/libs to 'libs' folder of your project.
In google-play-services_lib project, edit libs/google-play-services.jar.properties . The <path> in doc=<path> should point to the subfolder reference of the folder docs, which you created in step 3.
In Eclipse, do Project > Clean. Done, javadoc is now linked.
I'm trying to get ActionBarSherlock and the ViewPagerIndicator libraries set up for my projects, but I seem to be running into a few issues. I sent Jake Wharton (The developer) a few messages earlier about it, and got a few replies but couldn't get anywhere - and I think he got busy with a few other things.
What my issue is, For both VPI and ABS
Both libraries open up without any errors, and I'm using compiler version 1.6 for all as is required.
The funny thing is, if I load in the samples that are provided - they work fine and link to his library; but when I go to add the library to my project - the above happens.
Where to store the actual library project does not matter, as long as you use a relative link to reference it. Check out the Library Projects - Development considerations:
Library project storage location
There are no specific requirements on where you should store a library project, relative to a dependent application project, as long as the application project can reference the library project by a relative link. What is important is that the main project can reference the library project through a relative link.
You should always use the Eclipse ADT plugin to select and set up Library Project Reference, i.e. right-click project -> Properties -> Android -> Add, then in the opened Project Selection window, select the Library Project list here (of cause you should import them in the same Eclipse workspace as your Main Project). This will add a android.library.reference using relative path into project.properties as well as show relative path in the Android preference window:
android.library.reference.2=../../../../../Documents and Settings/yorkw/Desktop/JakeWharton-Android-ViewPagerIndicator-f09acb0/library
If you directly alter it using absolute path from project.properties as below:
android.library.reference.1=C:\\Documents and Settings\\yorkw\\Desktop\\JakeWharton-Android-ViewPagerIndicator-f09acb0\\library
Then after Eclipse refresh your project, you get the exact error described in your question, see my screenshot below:
Hope this helps.
While importing the libraries, make sure that you tick the "Copy projects int workspace" check box. The library projects need to be in the same workspace for them to work.
delete and import the project and lib again. build the lib project , add lib to project, still error shows.. rename the lib project. this worked for me ....
I'm creating a new app and I want to use some libraries like this:
https://github.com/JakeWharton/Android-ViewPagerIndicator
I had downloaded this library, added it to my workspace using New Android Project -> Create from existig source.
Went to properties > android, and checked Is Library.
Then I went to properties > android in my app project, and clicked add on the Libraries section, and chose the library, and It show me the library with a green V near it.
I've clicked ok, but couldn't use the library so I've opened the properties > android again, and there was a red cross near the library, and '?' under the "Project" column.
I can't understand why it's happening! It's really annoying, happened to me when I tried to add facebook API to my app, and I just gave up and copied the source to my project.
Thanks, Elad!
Copy every Library manually inside Eclipse Workspace, before importing it, as Eclipse seems to be silly if the Library lays somewhere else. Also symlinking a Library will not work.
For me, I just restart the eclipse and the added library works fine.
I mean first time it showing red marks after adding the library project.
Though eclipse main project and library project are in same workspace folder and no resources files are in outside of the project folder.
So, you can try with to restart your eclipse. Happy coding....