Android Google云端点错误:包MyApi不存在

Android Google云端点错误:包MyApi不存在,android,google-cloud-endpoints-v2,Android,Google Cloud Endpoints V2,我在运行MainActivity时收到以下错误:包MyApi不存在消息。StackOverFlow中也有类似的帖子,但解决方案不适合我 没有日志跟踪。发生的事情是,myApi这是googlecloudmodule后端类中API的名称,没有被识别,我真的不知道为什么 我的Api所在的类(模块后端) 试图从中访问API的类(模块应用程序) Build.gradle文件(模块后端) 顶级Build.gradle文件 根据,它应该是endpointsServer项目(路径::server),配置:“en

我在运行MainActivity时收到以下
错误:包MyApi不存在
消息。StackOverFlow中也有类似的帖子,但解决方案不适合我

没有日志跟踪。发生的事情是,
myApi
这是googlecloudmodule后端类中API的名称,没有被识别,我真的不知道为什么

我的Api所在的类(模块后端) 试图从中访问API的类(模块应用程序) Build.gradle文件(模块后端) 顶级Build.gradle文件
根据,它应该是
endpointsServer项目(路径::server),配置:“endpoints”)

可能与@DaltonCézane重复,这似乎是相同的错误,但该帖子上的解决方案对我面临的错误不起作用。根据,它应该是
endpointsServer项目(路径::server),配置:“endpoints”)
@saiyr它现在对我起作用了!当我在尝试之前错过endpoints framework客户端插件时,它还是崩溃了。非常感谢你的帮助。将你的评论粘贴为答案,这样我就可以将它标记为正确的答案。
import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiNamespace;
import com.joketellingapp.lacourt.jokesource.JokeSource;

import javax.inject.Named;

/** An endpoint class we are exposing */
@Api(
        name = "myApi",
        version = "v1",
        namespace = @ApiNamespace(
                ownerDomain = "backend.builditbigger.gradle.udacity.com",
                ownerName = "backend.builditbigger.gradle.udacity.com",
                packagePath = ""
        )
)
public class MyEndpoint {

    @ApiMethod(name = "sayHi")
    public MyBean sayHi() {
        MyBean response = new MyBean();
        response.setData(new JokeSource().getJoke());

        return response;
    }

}
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v4.util.Pair;

import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.extensions.android.json.AndroidJsonFactory;
import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
import com.google.api.client.googleapis.services.GoogleClientRequestInitializer;
import com.joketellingapp.lacourt.displayjoke.DisplayJoke;
import com.udacity.gradle.builditbigger.backend.myApi.MyApi;

import java.io.IOException;

class EndpointsAsyncTask extends AsyncTask<Pair<Context, String>, Void, String> {
    private static MyApi myApiService = null;
    private Context context;

    @Override
    protected String doInBackground(Pair<Context, String>... params) {
        if(myApiService == null) {  // Only do this once
            MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
                    new AndroidJsonFactory(), null)
                // options for running against local devappserver
                // - 10.0.2.2 is localhost's IP address in Android emulator
                // - turn off compression when running against local devappserver
                .setRootUrl("http://10.0.2.2:8888/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
                // end options for devappserver

            myApiService = builder.build();
        }

        context = params[0].first;
//        String name = params[0].second;

        try {
            return myApiService.sayHi().execute().getData();
        } catch (IOException e) {
            return e.getMessage();
        }
    }

    @Override
    protected void onPostExecute(String result) {
//        Toast.makeText(context, result, Toast.LENGTH_LONG).show();
        Intent intent = new Intent(context, DisplayJoke.class);
        intent.putExtra(DisplayJoke.JOKE_KEY, result);
        context.startActivity(intent);

    }


}
apply plugin: 'com.android.application'
apply plugin: 'com.google.cloud.tools.endpoints-framework-client'

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2'
    }
}

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.joketellingapp.lacourt.jokeapp"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

//    implementation project(path: ':backend', configuration: 'endpoints')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.google.android.gms:play-services-ads:11.8.0'

    implementation 'com.google.api-client:google-api-client:1.23.0'
    implementation 'com.google.http-client:google-http-client-android:1.23.0'
    implementation 'com.google.code.findbugs:jsr305:3.0.1'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    api project(':jokeSource')
    api project(':displayjoke')
    api project(path: ':backend', configuration: 'endpoints')
//    api project(path: ':backend')
}
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2'
        classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.3'
    }
}

repositories {
    jcenter()
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'com.google.cloud.tools.appengine'
apply plugin: 'com.google.cloud.tools.endpoints-framework-server'

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

appengine.run.port = 8888

dependencies {
    implementation 'com.google.endpoints:endpoints-framework:2.0.9'
    implementation 'javax.inject:javax.inject:1'

    implementation 'javax.servlet:servlet-api:2.5'
    implementation 'com.google.api-client:google-api-client:1.23.0'
    implementation 'com.google.http-client:google-http-client-android:1.23.0'

    compile project(path: ':jokeSource')
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'com.google.guava:guava:22.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir;
}