我一直堅持建立在App Engine端點平臺上的api連接。將生成的庫附加到我的Android客戶端後,使用它並構建一個應用程序,它總是說我的Api或Api $ Builder沒有找到(在運行時)。在編寫代碼或編譯時,它清晰可見且易於訪問。
我已經試過兩種不同的方法: - 將Maven的AppEngine上生成的.jar:endpoints_get_client_lib目標 - 將通過同一個目標
這兩個方法所產生的這些類的源使類可見並且在運行時仍然可以使用NoClassDefFound(當我實際調用它時)和一個錯誤,該類無法被dalvikvm找到。
我在訂單/導出選項卡中選擇了引用庫。雖然它在最新的位置(與其他任何嘗試)。我也檢查了Android 5.0 lib以及Android私有庫(取消選中了Android依賴關係和Maven依賴關係 - 沒有與Maven的選中關係)。
值得一提的是,當我在Eclipse中使用GAE插件(沒有maven)創建測試項目時,它完美運行。我無法弄清楚問題出在哪裏。
我可以提供任何您希望解決此問題的信息。請在評論中提問,以便更新所需信息。
我的代碼在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>
的POM我API應用程序:
<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 2014年1月11日:
Android清單:
<?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>