I am trying to implement the Google Play Game Services leaderboard found here. I imported the library BaseGameUtils, made it a library and added it to my main project. But there is a little red X and a red ! on my projects (see below picture).
Also, it says that the C:\Users\lyonsmg\Downloads\android-samples-master\BaseGameUtils\bin is missing in my Android Dependencies for my main project, BibleTriviaLite (see below picture).
What am I doing wrong? I was able to import the google-play-services_lib correctly but not the BaseGameUtils. How can I fix this?
Check the project properties for BaseGameUtils. Go to Project Properties | Android and check that it's targeting a valid Android target (there should be exactly one target checked) that's API level >= 8.
Check that BaseGameUtils is referencing google-play-services_lib as a dependency. To do this, go to Project Properties | Android and look at the References section. If there is nothing there, add a reference to google-play-services_lib.
Check that both google-play-services_lib and BaseGameUtils are set up as library projects. Go to Project Settings | Android and verify that both have the "Is Library" checkbox checked.
Clean and rebuild everything.
Hope this helps!
I was having the same problem and I think it was because you haven't added the google-play-service.jar to the BaseGameUtils project. I did this in eclipse by finding an error in the project, I used GamesClient in BaseGameActivity.java on the method getGamesClient() and hovered my mouse over GamesClient until the dropdown box appeared. I then clicked fix project setup. On the popup window click add google-play-service.jar (the 2nd one in the list) then click ok. This fixed the error for me. Hope it helps.
For me the problem was the google doc, imho. If i import a project , set it as lib, and add it as a reference to my code/project I would have never thought I would have to add it to compile path manually as well ( of course i want to compile it , no?) . Everything was set like above, I retested three times. Didn't work. BaseGameUtils would'n find the reference of com.google...gsm. Only if I manually add google play service library project to java build path under projects for the project BaseGameUtils it would a compile. (Eclipse 4.3.0)
from the short instructions by Google's github doc
If you're using Eclipse...
Start Eclipse
Import the desired sample (Project | Import | Android | Existing Android Source)
Import the Google Play Services library project (available for download through the SDK manager). Make sure that the sample is REFERENCING the library project (Project Properties | Android | References)
Import libraries/BaseGameUtils AS A LIBRARY Make sure that the sample is REFERENCING the library project (Project Properties | Android | References)
Now jump to the Modify IDs, compile and run section and continue to follow the instructions there.
Related
"AIDE" is an IDE for Android. It handles Java, Native Development, HTML dev, etc.
More specifically, I am trying to understand how I import a template LibGDX project started in AIDE, and open the project for running in the normal IntelliJ IDE, not the specific JetBrains Android Emulator version.
I imported the project, but cannot understand how to compile and execute the project, and I suspect I have imported the project incorrectly.
Can anyone help me to understand the process for this?
For IntelliJ 15, you must click "Import Project" on the into screen:
You then locate the ".project" file under "gdx-game" (or "gdx-game-android", but eventually you need to add both), and select it.
You will then configure the project settings, such as directory. You select
"$project_name$" if it is not already checked. You will also click
"Open Project Structure After Import":
Enter the name for the main project, and select the main SDK for the project:
You now navigate to the "Modules" section, and then rename the module ("project") from "$project_name$" to "gdx-game" (if you are in fact currently importing the "gdx-game" project).
You must also select the proper Module SDK to use in compilation of the project.
For "gdx-game", this would be a normal Java SDK such as Java SDK 1.7.
For "gdx-game-android", this would be "Project SDK (Android API 21 Platform)" by default, but if it does not appear you can select "Android 21 Platform(java version "1.7.0_79")":
You will now click the addition symbol, also pictured above (circled in red in image 4), in order to import the next module of the project ("gdx-game" or "gdx-game-android").
Again, you will navigate to the appropriate folder and locate the second ".project" file.
Upon import of the module, rename it in the same manner as you did with the first module. Alter it's SDK as well.
This should be all you need for a basic import of a project, but you may need to add libraries and such, depending on your projects needs obviously.
So I am fairly new to Java, and I am trying to add this library to my project. The problem is that Android studio 0.3.6 doesn't have a simple way of doing that and all the answers I searched either reference an older version of Android Studio, or describe how to import an external project (source code, not jar file).
After reading a little, I got to the conclusion that manually adding the jar file would be the best way (manual copy/paste and gradle edits) but as I said, I'm fairly new to this technology and don't know where to place the file nor what lines I need to add to the gradle files.
Can someone help me?
UPDATE 1:
I finally made the IDE recognize the .jar file (I get autocomplete and class recognition). The new problem is that I get the following error when compiling: Gradle: package com.google.gson does not exist. Here are the steps I took to import the library:
Creat a folder called libs in the main directory (src/main/libs should be the result)
Copy the .jar file in that directory
add the following line to the dependencies section in the build.gradle file in your project: compile files('libs/gson-2.2.4.jar'). It should look something like this now:
dependencies {
compile 'com.android.support:support-v13:+'
compile files('libs/gson-2.2.4.jar')
}
Recompile the project (not sure if necessary, but I did it)
Right click on the libs folder and select "Add as Library"
Since the GSON library is available in MavenCentral, there's an easy way to add it that avoids having to download an archive file and save it in your project.
Go to Project Structure > Modules > Your module name > Dependencies and click on the + button to add a new dependency. Choose Maven dependency from the list:
You'll get a dialog box where you can enter search terms or the fully-qualified Maven coordinate string. Since GSON is a common library for Android developers to use, it's actually given in this dialog as an example, with the fully-qualified name. You can type it in:
Hit OK on both dialogs and you should be good to go.
With these Maven dependencies, the build system will automatically download the library and cache it if hasn't done so already; it takes care of that for you.
If you had a library that wasn't available on MavenCentral, you could save the archive in a libs folder in your project, and from that module dependencies dialog, add a File dependency instead of a Maven dependency to take care of it.
If you edit your build.gradle file by hand, you need to click on the "Sync Project with Gradle Files" button in the toolbar to force Android Studio to pick up the changes and update your project. If you go through the Project Structure dialog, that's unnecessary.
There are lots of conflicting answers to this issue in Stack Overflow because the functionality for this is in flux as the necessary features are implemented; it has been really broken before. These instructions should work properly for 0.3.6, and things will get a little easier in 0.3.7 and later.
I had the same issue. The new version of Android Studio (0.3.6) removed some necessary features to add an existing library to a project using the IDE. So you have to do this manually.
Adding the library into the build folder "<project>\App\build\libs\" will break the project on "menu > build > clear project / rebuild project".
Updated solution
My solution is to generate a new folder inside "<project>\<app name>\src\main\libs\" and add the library here. Now you have to change your "<project>\<app name>\build.gradle" by adding the following (my example shows the value for android-support library:
dependencies {
compile 'com.android.support:support-v4:13.0.0'
compile 'com.android.support:support-v13:13.0.0'
compile files('libs/gson-2.2.4.jar')
}
Now select the library in "project View" by right click and select "Add as library... > level > Global library". This will fix an import com.google.gson.Gson; issue.
Maybe you still cannot build. In this case you shall check you project module settings and see if there is an error for Gson dependency. I let Android Studio fix this issue by hitting a "small red bulb icon > add dependency" in the lower right corner of module settings dialog. Now it does not show me no errors anymore on build.
Now we have only one remaining problem: The project does lose the library reference on project close. So we have to add the library on open again. Maybe this is an issue of Android Studio 0.3.6. Mario filed a bug report.
BTW: I upvoted this question because I searched without success for a working solution in the internet. I think beginners will always fail to work with the Android developer tutorials of Google when they are forced to deal with the support library.
Update / Recommendation
Unfortunately I did not get AS 0.3.6 working properly. There are to many issues - at least when adding another module with different namespace. So I switched to the origin IDE: IntelliJ IDEA 12 community Edition. It's free and works for me. I did all the stuff in 2 hours which need days using broken Android Studio. I have no idea what forces Google to build its own IDE based on IntelliJ IDEA without additional benefits / noticeable features when the latter works like a charm.
Running Android Studio 0.4.0
Solved the problem of importing jar by
Project Structure > Modules > Dependencies > Add Files
Browse to the location of jar file and select it
For those like manual editing
Open app/build.gradle
dependencies {
compile files('src/main/libs/xxx.jar')
}
I posted the same to
importing jar libraries into android-studio
putting a duplicate here just in case you stumble into this post instead
Click on ProjectName->Libs folder.Paste that jar file into that folder.
Just refresh the project.You are done.
Using Android Studio 0.8.2, I had to do the following (supposing the library you're trying to add is called MyExternalLib):
In the "app/libs" folder on the hard disk, create a sub-folder "MyExternalLib", and copy the external library into that folder.
In the file "app/build.gradle", inside the block named "dependencies", add the line compile project('libs:MyExternalLib')
In the file "settings.gradle", add the line include ':app:libs:MyExternalLib'
Click the button "Sync Project with Gradle Files"
Create a new library module
It is good development practice to group functionality that you may reuse in other apps inside a library module. To create a library module inside the BuildSystemExample project:
Click File and select New Module.
On the window that appears, select Android Library and click Next.
Leave the default module name (lib) unchanged and click Next.
Select Blank Activity and click Next.
Type "LibActivity1" on the Activity Name field and click Finish.
The project now contains two modules, app and lib, with one activity in each module.
https://developer.android.com/sdk/installing/studio-build.html
So I'm trying to implement jfeinsteins slide menu into my application, but before I do that I want to get a good demo, so I know how to implement it. Problem is that I'm stuck.
this is where I'm getting the library.
https://github.com/jfeinstein10/SlidingMenu
This is the project I'm trying to implement it in.
https://github.com/baruckis/Android-SlidingMenuImplementation
I did this part for the set up.
In Eclipse, just import the library as an Android library project. Project > Clean to generate the binaries you need, like R.java, etc.
,but I'm not sure I'm completely understanding this part.
Then, just add SlidingMenu as a dependency to your existing project and you're good to go!
how do I add slidingMenu as a dependency. Also, the error I'm receiving is SlidingMenu cannot be resolved to a variable, SlidingMenu cannot be resolved to a type.
Please can someone help me answer this!? Am I close?
To add a dependancy to an existing project, select the project containing your code (the one you want the dependancy to attach to), right click the project in the Package Explorer and select Properties.
In the Properties window, select Android and ensure that the library projects are added in the Library section. Click add to add an existing project in the workspace to the project as a dependancy.
It may also be worth checking dependancies in the Java Build Path too. Here you can ensure the correct .jar files are correctly assigned to your projects.
I was stuck at this place too. Please follow the below steps.
After downloading the library. In eclipse, go to New->project->android existing project
After downloading SlidingMenuImplementation, add this to eclipse similar to the way above.
I hope till here you have done. Next, right click on the SlidingMenuImplementation project --> properties --> Android --> Below the target window, you'll find references.
Add the Slidemenu library there. Once done clean the project. The errors are gone.
Please note, this supports only Android 4 and above. For lower versions use ActionBarSherlock.
Is anyone else having problems importing a project with ActionBarSherlock?
I have a total of 100 errors and 17 warnings. This worked perfectly in Eclipse. I followed the steps to create a Gradle build file. There were no import errors until I tried to build the Project.
I also tried re-downloading ABS fresh and replace into my project.
Were there known issues with ABS and IntelliJ? (which of course Android Studio is now based)
Here are a few errors I'm seeing:
java: ...
Workspace/ActionBarSherlock/src/com/actionbarsherlock/app/SherlockFragment.java:4: cannot find symbol
symbol : class Fragment
location: package android.support.v4.app
java: ... Workspace/ActionBarSherlock/src/com/actionbarsherlock/app/SherlockListFragment.java:4: cannot find symbol
symbol : class ListFragment
location: package android.support.v4.app
java: ...
Workspace/ActionBarSherlock/src/com/actionbarsherlock/widget/SuggestionsAdapter.java:33:
package android.support.v4.widget does not exist
Any help really appreciated
Edit: Seems there are no issues using Standard IntelliJ IDEA. Many guides online for setting it up with ABS. Also as Jake mentioned, he's actually been developing the thing in IntelliJ
Here is an example guide:
http://android-wtf.com/2012/09/how-to-configure-actionbarsherlock-with-intellij-idea/
However, I'm still unsure why its not working in Android Studio
Edit2: solution in answer below. In Short: (I downloaded abs latest version, extracted, deleted the old version of abs from my project, then file > import module... to import actionbarsherlock directory into my existing project. Nb, in my particular case I had an issue with junit compilation error and needed to delete \test\junit\ )
Seems there's a lot of general issues on importing modules to Android Studio, not just ActionBarSherlock, this answer might also address those. (However the last steps relating to junit are particular to abs)
The steps below allowed me to get ActionBarSherlock running with no issues.
1) Download latest ABS here: http://actionbarsherlock.com/
2) Extract ABS you should have a directory in there called "actionbarsherlock". Copy that to your Android Studio workspace. and rename to ActionBarSherlock (changed casing) -- > I now have my Android Studio Projects under \*documents*\Android Workspace\ As opposed to \Eclipse Workspace\
So you should now have something like :
\*documents*\Android Workspace\ActionBarSherlock\
Along with your main project maybe:
\*documents*\Android Workspace\TestProject\
3) Open Android Studio load your TestProject then goto File> Import Module... Now navigate to ActionBarSherlock under \*documents*\Android Workspace\ActionBarSherlock\
Click Ok and next all the way to finish. It will ask if you want to set a dependancy to the new Module (or at least mine did) click OK
4) at this point when compiling I was getting errors in \ActionBarSherlock\test\ complaining about Junit. I simply deleted the \Test\ directory from my ABS Module under project view. Right click \test\ > Delete.... You could also include the junit jar file but I don't think its necessary
5) you should now be able to compile without errors
Hopefully that helps someone.
Essentially though, I needed to re-download a completely fresh ABS, expunge my old project's ABS (which was probably quite old) then Import Module...
This works for me..
first, followed an answer provided by wired00
and I made some changes from here.
I made a build.gradle file in ActionBarSherlock library project by Generate Gradle build files from Eclipse.
edit build.gradle(for ActioBarSherlock library project) , Add a line in dependencies {}
compile files('libs/android-support-v4.jar')
edit build.gradle(for my project), delete compile files('libs/android-support-v4.jar') and add compile project(':abs') abs should be ActionBarSherlock library project name.
edit settings.gradle, add ,':abs'
delete android-support-v4.jar files except the one in the ActionBarSherlock library project
I encountered similar issue, but due to a separate problem, I can't download the latest ActionBarShelock to fix the problem as wired00 described.
If you need to stick with your existing ABS version, see if this works for you:
Click File->Project Structure.
You should see 'ActionBarSherlock' in the module list, click it.
Click the 'Dependencies' tab, very likely you do not have android support library v4 in there.
Click the '+' button at the bottom, and add android-support-v4 as a dependency. If you imported the project from Eclipse, Android Studio may have already imported the support JAR file as a library and you can use it directly. Otherwise, you may need to use the 'jars or directories' option and select the support jar file from a directory.
If your main module or other modules are also using the support library, you may need to change the setting 'Compile' to 'Provided' if you get 'DEX Already Added' errors.
You should be able to compile your ABS mobule now. If you get 'hamcrest' or 'junit' compilation errors, you may delete the 'test' folder in your ABS project as wired00 mentioned.
i also faced the same issue. i even follow the steps similar to importing ABS Library. But i was still getting the same error. Finally i solved this issue.
Solution: After following the steps similar for importing ABS Library,
Re-compile your project (Right click on your project and click on 'Compile Module "YourApp" ')
Re-compile the Library Project (Right click on Library project and click on 'Compile Module "library" ')
That's it..
I'm interested in running the Android Support library demo projects for the v4 library.
Using the Android SDK manager I've installed the Eclipse plugins, and APIs from 2.2 to 4.0.1. There are several issues involved, and the sample project as provided is far from running on my configuration, as downloaded.
To reproduce this error:
Install SDK and Eclipse Juno
Import the sample v4 compatibility project using File --> New --> New Project and choose "from existing code", targeting, for example, the Support4Demos folder in <Android-sdk-path>/extras/android/support
Open the file AccessibilityManagerSupportActivity.java. The following errors appear.
Open res/values-v11/styles.xml. The following errors occur.
How do I get rid of these errors? I'd also like to understand why they are appearing so I can fix them in the future.
Thanks!
Clean solution is to:
Right-click your project.
Choose "Android Tools"
Choose "Add support library".
Install the appropriate support library (the newest)
I can't really answer you on the why this problem happens, but I'm guessing the Android team doesn't supply the Android support library, because it's changing all the time, so not to get stuck on some older version, they want us to supply it on our own.
If errors still persists or new errors come up, right-click the project again and choose "Android tool" -> "Fix project properties"
Update: In conjuction to my answer, the way to remove the rest of the errors is to import the project another way than you did.
Select File -> New -> Other
Click Next
Write Android Sample
Select Android sample Project and click Next
Now add the Android support librarys as described above.
You will get errors still however. To fix these, do the following:
Right-click your project and select "Properties"
Select Android
Select an SDK version equal to 3.0 or above
Select Ok and clean the project from the project menu.
All done ;-)
Now you won't be able to run the sample project on devices lower than Android 3.0.
The reason is because of some dependencies on some themes and settings, that wasn't added before Android 3.0 apparently.
It doesn't make sense why Google did this, but they did. You could try to remove the SDK +11 (Android 3.0) specific dependencies, but it will take some time - there are more errors than you actually see - especially in the XML files.
You have to add the v4 support library.
In order to do that , please follow these steps :
Select your project.
Click on Project from the menu.
Select Properties.
Click on Java Build Path.
Select the Libraries tab.
Click on Add External JARs.
Select the main directory of the Android SDK that you installed, then go to extras -> android -> support -> v4 , and then select android-support-v4.jar and click on Open.
Click OK.
This should remove the errors.
Please check your libs folder has android-support-v4.jar is present or not. if not add this jar file in libs folder.Just copy the android-support-v4.jar from any project and paste it to the libs folder of your project
I spent a whole night on this but can not solve this problem.
I finally solved the by accident: change some file in the demo and save, then change it back, this cleared all the errors. I think when you change some file and save, eclipse build the project and generate the R.java.