gpt4 book ai didi

java - App Engine 端点库 - NoClassDefFound 适用于我的 Api 及其 $Builder

转载 作者:太空狗 更新时间:2023-10-29 15:01:07 26 4
gpt4 key购买 nike

我无法连接到在 App Engine Endpoints 平台上构建的 API。在我将生成的库附加到我的 Android 客户端后,使用它并构建一个应用程序,它总是说我的 Api 或 Api$Builder 未找到(在运行时)。在开发代码或编译时,它清晰可见且可访问。

我尝试了两种不同的方法:- 附加由 maven appengine:endpoints_get_client_lib 目标生成的 .jar- 附加由同一目标生成的这些类的源代码

这两种方法都使类在运行时仍然可见和可用,但存在异常 NoClassDefFound(当我实际调用它时)和 dalvikvm 无法找到该类的错误。

我在订单/导出选项卡中选择了引用的库。尽管它处于最新位置(与任何其他位置一起尝试过)。我还检查了 Android 5.0 库以及 Android 私有(private)库(未选中 Android 依赖项和 Maven 依赖项 - 也不适用于已选中的 Maven)。

值得一提的是,当我使用 GAE 插件(没有 Maven)在 Eclipse 中创建测试项目时,它运行良好。我无法弄清楚问题出在哪里。

我可以提供解决此问题所需的任何信息。请在评论中提问,以便我更新所需信息。

我在 Android 应用程序的 MainActivity 中的部分代码:

protected TestUser callApi() throws IOException
{
Api.Builder api = new Api.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null);
return api.build().hello("ANY").execute();
}

我的 API 代码:

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.google.api.server.spi.config.Named;
import com.test.user.Contact;
import com.test.user.TestUser;
import com.test.user.status.Status;
import com.test.utils.Utils;

/** An endpoint class we are exposing */
@Api(
name = "api",
version = "v1",
description = "My Own Api",
namespace = @ApiNamespace(
ownerDomain = "com.test.server",
ownerName = "com.test.server",
packagePath = ""),
scopes = { Utils.EMAIL_SCOPE }
)
public class ApiService
{
/**
* Api Method for Testing purposes.
*
* @param name
* @return
*/
@ApiMethod(name = "hello")
public TestUser hello(@Named("name") String name)
{
TestUser response = new TestUser();
response.setId(123);
response.setName(name);

return response;
}
}

我的 Android 项目的 POM:

<properties>
<!-- use UTF-8 for everything -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<appengine.app.version>2</appengine.app.version>
<appengine.target.version>1.9.14</appengine.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
<!-- Compile/runtime dependencies -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>${appengine.target.version}</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-endpoints</artifactId>
<version>${appengine.target.version}</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.19.0</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.19.0</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-android</artifactId>
<version>1.19.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.9.0-rc.1</version>
<configuration>
<sdk>
<platform>21</platform>
</sdk>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

我的 API 应用程序的 POM:

<pluginRepositories>
<pluginRepository>
<id>google-staging</id>
<name>Google Staging</name>
<url>https://oss.sonatype.org/content/repositories/comgoogleappengine-1004/</url>
</pluginRepository>
</pluginRepositories>

<properties>
<appengine.app.version>1</appengine.app.version>
<appengine.target.version>1.9.14</appengine.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!-- Compile/runtime dependencies -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>${appengine.target.version}</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-endpoints</artifactId>
<version>1.9.14</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.jdo</groupId>
<artifactId>jdo-api</artifactId>
<version>3.1-rc1</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>

<dependency>
<groupId>com.googlecode.objectify</groupId>
<artifactId>objectify</artifactId>
<version>5.1</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>${appengine.target.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>${appengine.target.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<outputDirectory>target/${project.artifactId}/WEB-INF/classes</outputDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archiveClasses>true</archiveClasses>
<webResources>
<!-- in order to interpolate version from pom into appengine-web.xml -->
<resource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
</configuration>
</plugin>

<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.9.14</version>
<configuration>
<enableJarClasses>false</enableJarClasses>
<port>8888</port>
<address>0.0.0.0</address>
</configuration>
</plugin>
</plugins>
</build>

编辑 14:43 1.11.2014:

Android list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.client"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="21" />

<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/abc_max_action_buttons" />
<activity
android:name="MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

最佳答案

此错误通常意味着在服务器上找不到所需的 jar。您没有在 Eclipse 中看到错误,因为您已将所有必需的 jar 添加到类路径中。

在 Eclipse 中,选择您的项目并单击 Problems 选项卡。查看是否有任何警告说“...将无法在服务器上使用...”。右键单击此警告并选择“复制”选项。

请注意,另一种可能性是您在该文件夹中有多个所需 jar 的副本,在这种情况下,您应该删除所有副本,添加正确的 jar,然后清理项目。

关于java - App Engine 端点库 - NoClassDefFound 适用于我的 Api 及其 $Builder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26689881/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com