maclir
maclir

Reputation: 3309

android studio BaseGameUtils

I'm trying to implement Google Play Game Services, and I need to have BaseGameUtils as a library in my project. Following google tutorials I could not find a way to include this in a project that I already have in android studio. Importing manually in Android Studio...

How should I import BaseGameUtils in a project that already exists? What is the best practice?

Should I copy the whole BaseGameUtils in the libs folder in my module? Or should I copy BaseGameUtils in my project folder?

\Project
|--\module
|--|--\libs
|--|--|--android-support-v4.jar
|--|--|--...
|--|--|--\BaseGameUtils
|--|--|--|--...
|--|--\src
|--|--|--...

or

\Project
|--\module
|--|--\libs
|--|--|--android-support-v4.jar
|--|--|--...
|--|--\src
|--|--|--...
|--\libraries
|--|--\BaseGameUtils

Except in the gradle file (in BaseGameUtils) should I mention anywhere else that BaseGameUtils is a library?

Upvotes: 7

Views: 5041

Answers (3)

Nathan Bird
Nathan Bird

Reputation: 932

I have been having the same problem for a long time, but I finally found a solution.

  1. Open your project
  2. Open File > New > Import module
  3. Input your BaseGameUtils library file path
  4. Open your build.gradle file (ProjectName/app/build.gradle)
  5. Add compile project(':BaseGameUtils') to the first line of the dependencies list
  6. Sync project

Upvotes: 1

Rohit Goyal
Rohit Goyal

Reputation: 1539

  1. Open File > Project Structure
  2. Click on the + sign in the top left corner
  3. Select "Import Eclipse ADT Project" and click next
  4. Select BaseGameUtils path on your computer like "/android-basic-samples-master/BasicSamples/libraries/BaseGameUtils" and in the next screen you will see module name something like ":BaseGameUtils" then click ok
  5. Click next you would be able to see BaseGameUtils module in your modules
  6. Select your app in the project structure, go to dependencies, click on + sign and select "module dependency" and then select "BaseGameUtils"
  7. Click Ok and your gradle will be rebuild with all the access to BaseGameUtils functions/classes.

Upvotes: 4

IanB
IanB

Reputation: 3489

In Eclipse, you define BaseGameUtils as a library project and add it as a reference to your project.

These instructions cover Android Studio and were (I think) written by the guy who wrote the Google Play Game Services sample programs :

https://github.com/playgameservices/android-samples/blob/master/README.md

They appear to answer you question.

Update:

In Eclipse, what I did was to copy GameHelper and BaseGameActivity (the two sources in BaseGameUtils) into my project. I then added the dependencies (resources). This approach worked fine. However, since I did this Google made this video which advises you against this approach. This is why I answered the question in the way that I did.

https://developers.google.com/live/shows/5936979195723776

Upvotes: 0

Related Questions