使用Google端点的NoSuchMethodError

时间:2015-05-16 09:06:12

标签: android google-app-engine google-cloud-endpoints

我正在使用Google App Engine创建Android应用。为了使用GCM(Google Cloud Messaging),我在Android Studio中创建了一个GCM模块。此模块提供了一个示例代码,用于在数据存储区中注册设备。

昨天一切运作良好,虽然没有任何改变,但当我尝试注册我的设备时出现此错误:

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

我不知道符号<init>()V到底意味着什么,但我找到了由Android Studio的Google插件生成的Cursor类,此处:

enter image description here

这是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;
    }
}

最后,这是我的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
    }
}

因为我在相关代码中没有改变任何内容,所以我真的无法理解发生了什么,我发现网上没有任何用处。

提前感谢您的帮助。

编辑:后端日志中的StackTrace

enter image description here

1 个答案:

答案 0 :(得分:1)

正在寻找空构造函数:method init()v not found

看来这可能是因为Cursor.java已从您的<module>/build/classes/main(或<module>/build/exploded-app/WEB-INF/classes/main)中提取,而实际上它应该从库appengine-api-1.0-sdk-<version>.jar中拉出来。< / p>

您是否以某种方式将Cursor.java的源添加到项目src文件夹中? App Engine构建在<module>/build/exploded-app创建可运行的构建,并且游标类通常来自<module>/build/exploded-app/WEB-INF/lib/appengine-api-1.0-sdk-<version>.jar