Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BaseGameUtils GoogleApiClient.ApiOptions cannot be resolved to a type

After importing BaseGameUtils project as a library and fixing a couple of errors i came across these errors:

GoogleApiClient.ApiOptions mGamesApiOptions = null;
GoogleApiClient.ApiOptions mPlusApiOptions = null;
GoogleApiClient.ApiOptions mAppStateApiOptions = null;

the errors say GoogleApiClient.ApiOptions cannot be resolved to a type. other errors i got:

public void setGamesApiOptions(GoogleApiClient.ApiOptions options) {
    doApiOptionsPreCheck();
    mGamesApiOptions = options;
}

they say mGamesApiOptions cannot be resolved to a variable and the same as before for the GoogleApiClient.ApiOptions. i've already referenced the google_play_services_lib to the GameBaseUtils. ive looked on the internet for some explanation without succes, the only thing i found is this https://code.google.com/p/google-api-java-client/wiki/Setup but didn't help much either because i didn't really understand what to do, can anyone help? (btw i use eclipse)

like image 416
zenta Avatar asked May 24 '14 19:05

zenta


2 Answers

came across the same problem just now.. this solution worked

Use the code available here instead: https://gist.github.com/EmmanuelVinas/ef09a35bcc805ba6deb3

Just cut everything from the imports of GameHelper.java (BaseGameUtils) to the end of it and then paste the contents of that gist as a replacement.

like image 120
A. Adam Avatar answered Sep 18 '22 20:09

A. Adam


I'm having the exact same problem with my app. I think they must have changed something in the most recent update to GameHelper.java. Here's something I tried, but just so you know, this only got rid of the errors so I could compile my code, it doesn't fix the source of the problem.

// Api options to use when adding each API, null for none
Games.GamesOptions mGamesApiOptions = null;
Plus.PlusOptions mPlusApiOptions = null;
Api.ApiOptions mAppStateApiOptions = null;

I also changed the methods further down so that the Classes matched...

/**
 * Sets the options to pass when setting up the Games API. Call before
 * setup().
 */
public void setGamesApiOptions(Games.GamesOptions options) {
    doApiOptionsPreCheck();
    mGamesApiOptions = options;
}

/**
 * Sets the options to pass when setting up the AppState API. Call before
 * setup().
 */
public void setAppStateApiOptions(Api.ApiOptions options) {
    doApiOptionsPreCheck();
    mAppStateApiOptions = options;
}

/**
 * Sets the options to pass when setting up the Plus API. Call before
 * setup().
 */
public void setPlusApiOptions(Plus.PlusOptions options) {
    doApiOptionsPreCheck();
    mPlusApiOptions = options;
}

I was still getting errors so I finally just had to get rid of the second parameters of these addApi() method calls because they weren't accepting these Class types. Fortunately the addApi() method doesn't need the options parameter, but removing it pretty much defeats the entire purpose of having these variables in the first place.

if (0 != (mRequestedClients & CLIENT_GAMES)) {
    builder.addApi(Games.API); //, mGamesApiOptions);
    builder.addScope(Games.SCOPE_GAMES);
}

if (0 != (mRequestedClients & CLIENT_PLUS)) {
    builder.addApi(Plus.API); //, mPlusApiOptions);
    builder.addScope(Plus.SCOPE_PLUS_LOGIN);
}

if (0 != (mRequestedClients & CLIENT_APPSTATE)) {
    builder.addApi(AppStateManager.API); //, mAppStateApiOptions);
    builder.addScope(AppStateManager.SCOPE_APP_STATE);
}

I really hope someone comes up with a real solution or they update the GameHelper file. This was a pretty annoying problem. Sorry I couldn't be more helpful.

EDIT: I found when they changed this code in the GitHub project. However these changes were committed over 3 months ago, so I'm very confused as to why no one else has had this problem. Here's what it looks like:

-    // Client objects we manage. If a given client is not enabled, it is null.
-    GamesClient mGamesClient = null;
-    PlusClient mPlusClient = null;
-    AppStateClient mAppStateClient = null;
+    // the Google API client builder we will use to create GoogleApiClient
+    GoogleApiClient.Builder mGoogleApiClientBuilder = null;

-    // What clients we manage (OR-able values, can be combined as flags)
+    // Api options to use when adding each API, null for none
+    GoogleApiClient.ApiOptions mGamesApiOptions = null;
+    GoogleApiClient.ApiOptions mPlusApiOptions = null;
+    GoogleApiClient.ApiOptions mAppStateApiOptions = null;
+
+    // Google API client object we manage.
+    GoogleApiClient mGoogleApiClient = null;
like image 26
solarbabies Avatar answered Sep 19 '22 20:09

solarbabies