【问题标题】:Errors using LibGdx with Google Play Services/BaseGameUtils (Gradle)将 LibGdx 与 Google Play Services/BaseGameUtils (Gradle) 一起使用时出错
【发布时间】:2014-05-22 21:04:46
【问题描述】:

我正在使用来自https://github.com/playgameservices/android-samples 的 Eclipse、LibGdx 1.0.1、最新的 Google Play Lib 和最新的 BaseGameUtils

(Gradle 项目)

我的 BaseGameUtils 有一些错误

GameHelper.java

// Api options to use when adding each API, null for none
GoogleApiClient.ApiOptions mGamesApiOptions = null; //error with this line
GoogleApiClient.ApiOptions mPlusApiOptions = null; //error with this line
GoogleApiClient.ApiOptions mAppStateApiOptions = null; //error with this line

/**
 * Sets the options to pass when setting up the Games API. Call before
 * setup().
 */
public void setGamesApiOptions(GoogleApiClient.ApiOptions options) { //error with this line
    doApiOptionsPreCheck();
    mGamesApiOptions = options; //error with this line
}

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

/**
 * Sets the options to pass when setting up the Plus API. Call before
 * setup().
 */
public void setPlusApiOptions(GoogleApiClient.ApiOptions options) { //error with this line
    doApiOptionsPreCheck();
    mPlusApiOptions = options; //error with this line
}

/**
 * Creates a GoogleApiClient.Builder for use with @link{#setup}. Normally,
 * you do not have to do this; use this method only if you need to make
 * nonstandard setup (e.g. adding extra scopes for other APIs) on the
 * GoogleApiClient.Builder before calling @link{#setup}.
 */
public GoogleApiClient.Builder createApiClientBuilder() {
    if (mSetupDone) {
        String error = "GameHelper: you called GameHelper.createApiClientBuilder() after "
                + "calling setup. You can only get a client builder BEFORE performing setup.";
        logError(error);
        throw new IllegalStateException(error);
    }

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(
            mActivity, this, this);

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

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

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

    mGoogleApiClientBuilder = builder;
    return builder;
}

所以我在你猜错的行上添加了//error with this line

就像我之前提到的,我相信我拥有最新的库,并且我确信我的项目已正确链接。我的AndroidManifest.xml 文件中也有必要的代码行。

【问题讨论】:

    标签: java android gradle libgdx


    【解决方案1】:

    Google Play 游戏服务 4.4 中的一些 API 更改尚未反映在 Android 示例项目 (https://github.com/playgameservices/android-samples/tree/master/BasicSamples/libraries/BaseGameUtils) 中或由 Google 记录(据我所知)。

    看看 G+ Android Developers 上的 cmets 条目:

    https://plus.google.com/+AndroidDevelopers/posts/8957tqzymuM

    您可以使用社区修改的 GameHelper,等待 Google 更新示例项目或反向到 GPGS 4.3。

    【讨论】:

    • 没问题。如果解决了问题,请点赞。
    • 我的声望不够高,哈哈。我在哪里可以获得 4.3?
    【解决方案2】:

    我使用了来自https://github.com/playgameservices/android-samples/tree/master/BasicSamples/libraries/BaseGameUtils/src/main/java/com/google/example/games/basegameutils 的源代码,但我的应用程序因以下错误而崩溃:

    java.lang.NullPointerException: Null options are not permitted for this Api at
    .. com.google.example.games.basegameutils.GameHelper.createApiClientBuilder(GameHelper.java:286    ) at 
    com.google.example.games.basegameutils.GameHelper.setup(GameHelper.java:319) at
    com.google.example.games.basegameutils.BaseGameActivity.onCreate(BaseGameActivity.java:105).
    

    我改变了 BaseGameActivity 的 onCreate 方法:

    @Override
    protected void onCreate(Bundle b) {
        super.onCreate(b);
        if (mHelper == null) {
            getGameHelper();
        }
        mHelper.setPlusApiOptions(new Plus.PlusOptions.Builder().build());
        mHelper.setup(this);
    }
    

    错误消失了。

    【讨论】:

      【解决方案3】:

      请改用此处提供的代码:https://gist.github.com/EmmanuelVinas/ef09a35bcc805ba6deb3

      只需剪切从 GameHelper.java 的导入到结尾的所有内容,然后粘贴该要点的内容作为替换。

      有效

      【讨论】:

        猜你喜欢
        • 2014-02-01
        • 2016-03-14
        • 1970-01-01
        • 2018-05-19
        • 1970-01-01
        • 2016-03-26
        • 1970-01-01
        • 1970-01-01
        • 2019-10-26
        相关资源
        最近更新 更多