0

I am creating an Android app using Google App Engine. In order to use GCM (Google Cloud Messaging), I have created a GCM module in Android Studio. This module provides a sample code that registers devices in the Datastore.

All was working well yesterday, and although nothing changed, I have this error when I try to register my device :

java.lang.NoSuchMethodError: com.google.appengine.api.datastore.Cursor: method <init>()V not found

I don't know what exactly means the notation <init>()V, but I found the Cursor class to be generated by the Google plugin of Android Studio, here :

enter image description here

This is the decompiled code inside Cursor.class :

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.google.appengine.api.datastore;

import java.io.Serializable;

public final class Cursor implements Serializable {
    private String webString;

    public Cursor(String webString) {
        this.webString = webString;
    }

    public String toWebSafeString() {
        return this.webString;
    }

    public static Cursor fromWebSafeString(String encodedCursor) {
        if(encodedCursor == null) {
            throw new NullPointerException("encodedCursor must not be null");
        } else {
            return new Cursor(encodedCursor);
        }
    }

    public boolean equals(Object o) {
        if(this == o) {
            return true;
        } else if(o != null && this.getClass() == o.getClass()) {
            Cursor cursor = (Cursor)o;
            return this.webString.equals(cursor.webString);
        } else {
            return false;
        }
    }

    public int hashCode() {
        return this.webString.hashCode();
    }

    public String toString() {
        return this.webString;
    }
}

Finally, this is my build.gradle :

// If you would like more information on the gradle-appengine-plugin please refer to the github page
// https://github.com/GoogleCloudPlatform/gradle-appengine-plugin

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.google.appengine:gradle-appengine-plugin:1.9.18'
    }
}

repositories {
    jcenter();
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'

sourceCompatibility = 1.7
targetCompatibility = 1.7

dependencies {
    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.18'
    compile 'com.google.appengine:appengine-endpoints:1.9.18'
    compile 'com.google.appengine:appengine-endpoints-deps:1.9.18'
    compile 'javax.servlet:servlet-api:2.5'
    compile 'com.googlecode.objectify:objectify:4.0b3'
    compile 'com.ganyo:gcm-server:1.0.2'
}

appengine {
    downloadSdk = true
    appcfg {
        oauth2 = true
    }
    endpoints {
        getClientLibsOnBuild = true
        getDiscoveryDocsOnBuild = true
    }
}

Because I changed nothing in the concerned code, I really can't understand what happened and I found nothing useful on the web.

Thank you in advance for your help.

Edit : StackTrace from the backend log

enter image description here

Chostakovitch
  • 965
  • 1
  • 9
  • 33

1 Answers1

1

It's looking for the empty constructor : method init()v not found

It appears this could be because Cursor.java is pulled from your <module>/build/classes/main (or <module>/build/exploded-app/WEB-INF/classes/main), when really it should just be pulled in from a library appengine-api-1.0-sdk-<version>.jar.

Have you added the source for a Cursor.java into your project src folder somehow? The App Engine build creates a runnable build at <module>/build/exploded-app and the cursor class is usually sourced from <module>/build/exploded-app/WEB-INF/lib/appengine-api-1.0-sdk-<version>.jar

Community
  • 1
  • 1
loosebazooka
  • 2,363
  • 1
  • 21
  • 32
  • In fact, the App Engine module used to generate the class `Cursor` as you can see in my post. However, when I looked the real class inside the SDK, it was a totally different code (with the constructor). I tried to remove the generated class and to build the project, but everytime it was re-generated. The only solution I found was to update to the new SDK `1.9.20`. Not the class is not generated anymore, but I still don't understand this behaviour. Thank you for your comment. – Chostakovitch May 18 '15 at 15:44
  • That's very strange, it does not do that for my installation using 1.9.18. – loosebazooka May 18 '15 at 15:46
  • Yes, I haven't found any similar issue. I assume this is a configuration problem, or a conflict problem, as I work with shared sources. – Chostakovitch May 18 '15 at 15:47
  • If it's not too much trouble, can you try with a clean build and 1.9.18? Usually something like `./gradlew clean assemble` or maybe just delete the `/build` directory and try again? I suspect that the Cursor class ended up in there some how and was never cleaned out. – loosebazooka May 18 '15 at 15:49
  • Before updating to `1.9.20` i've tried your two solutions. That's why I choosed the "radical" solution. :) – Chostakovitch May 18 '15 at 15:55