Domanda

I'm trying to create a GCM Demo Application for Android on Windows 7 following the "official" tutorial (http://developer.android.com/google/gcm/demo.html).

In particular, I am trying to create a server using Java App Engine as described in said tutorial:

To set up the server using a standard App Engine for Java:

  1. From the SDK Manager, install Extras > Google Cloud Messaging for Android Library. This creates a gcm directory under YOUR_SDK_ROOT/extras/google/ containing these subdirectories: gcm-client, gcm-server, samples/gcm-demo-client, samples/gcm-demo-server, and samples/gcm-demo-appengine.

  2. In a text editor, edit samples/gcm-demo-appengine/src/com/google/android/gcm/demo/server/ApiKeyInitializer.java and replace the existing text with the API key obtained above.

    Note: The API key value set in that class will be used just once to create a persistent entity on App Engine. If you deploy the application, you can use App Engine's Datastore Viewer to change it later.

  3. In a shell window, go to the samples/gcm-demo-appengine directory.

  4. Start the development App Engine server by ant runserver, using the -Dsdk.dir to indicate the location of the App Engine SDK and -Dserver.host to set your server's hostname or IP address:

    $ ant -Dsdk.dir=/opt/google/appengine-java-sdk runserver -Dserver.host=192.168.1.10 Buildfile: gcm-demo-appengine/build.xml

I have followed these steps, and I get the following error:

C:\Users\p\AppData\Local\Android\android-sdk\extras\google\gcm\samples\gcm-demo-appengine>ant -Dsdk.dir C:/Users/p/appengine-java-sdk-1.8.0 runserver -Dserver.host=192.168.44.1 Buildfile: gcm-demo-appengine/build.xml
Buildfile: C:\Users\p\AppData\Local\Android\android-sdk\extras\google\gcm\samples\gcm-demo-appengine\build.xml

init:

copyjars:

compile:
    [javac] Compiling 8 source files to C:\Users\p\AppData\Local\Android\android-sdk\extras\google\gcm\samples\gcm-demo-appengine\WebContent\WEB-INF\classes
    [javac] C:\Users\p\AppData\Local\Android\android-sdk\extras\google\gcm\samples\gcm-demo-appengine\src\com\google\android\gcm\demo\serer\ApiKeyInitializer.java:1: reached end of file while parsing
    [javac] AIzbSyBQdFestseFygh7Q22dxEfdsyc_k->
    [javac] ^
    [javac] 1 error

BUILD FAILED

"reached end of file while parsing" - as I understand it, this error is normally caused by missing brackets - however, all I've done is edit the ApiKeyInitializer.java file in Notepad to enter the API key; I have not touched any code! I have tried to find a solution online, but to no avail.

Does anyone know what might be causing this issue and how I could fix it? Many thanks in advance!

È stato utile?

Soluzione

I checked the ApiKeyInitializer.java file (I had it locally on my computer). It looks like a valid java class :

/*
 * Copyright 2012 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.android.gcm.demo.server;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import java.util.logging.Logger;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Context initializer that loads the API key from the App Engine datastore.
 */
public class ApiKeyInitializer implements ServletContextListener {

  static final String ATTRIBUTE_ACCESS_KEY = "apiKey";

  private static final String ENTITY_KIND = "Settings";
  private static final String ENTITY_KEY = "MyKey";
  private static final String ACCESS_KEY_FIELD = "ApiKey";

  private final Logger logger = Logger.getLogger(getClass().getName());

  public void contextInitialized(ServletContextEvent event) {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Key key = KeyFactory.createKey(ENTITY_KIND, ENTITY_KEY);

    Entity entity;
    try {
      entity = datastore.get(key);
    } catch (EntityNotFoundException e) {
      entity = new Entity(key);
      // NOTE: it's not possible to change entities in the local server, so
      // it will be necessary to hardcode the API key below if you are running
      // it locally.
      entity.setProperty(ACCESS_KEY_FIELD,
          "replace_this_text_by_your_Simple_API_Access_key");
      datastore.put(entity);
      logger.severe("Created fake key. Please go to App Engine admin "
          + "console, change its value to your API Key (the entity "
          + "type is '" + ENTITY_KIND + "' and its field to be changed is '"
          + ACCESS_KEY_FIELD + "'), then restart the server!");
    }
    String accessKey = (String) entity.getProperty(ACCESS_KEY_FIELD);
    event.getServletContext().setAttribute(ATTRIBUTE_ACCESS_KEY, accessKey);
  }

  public void contextDestroyed(ServletContextEvent event) {
  }

}

Perhaps you somehow deleted the contents of that file.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top