Java Android Studio appengine端点不包括生成器
在我的AndroidStudio项目中,我有两个模块:app,它是android模块,api,它是app引擎模块。应用程序引擎模块api是通过在AndroidStudio中创建端点应用程序引擎模块生成的 我有一个端点类,它是从一个名为Comment的objectify注释类生成的Java Android Studio appengine端点不包括生成器,java,android,google-app-engine,android-studio,google-cloud-endpoints,Java,Android,Google App Engine,Android Studio,Google Cloud Endpoints,在我的AndroidStudio项目中,我有两个模块:app,它是android模块,api,它是app引擎模块。应用程序引擎模块api是通过在AndroidStudio中创建端点应用程序引擎模块生成的 我有一个端点类,它是从一个名为Comment的objectify注释类生成的 package com.example.pontuse.api; import com.googlecode.objectify.annotation.Entity; import com.googlecode.ob
package com.example.pontuse.api;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
/**
* Created by pontuse on 2014-09-08.
*/
@Entity
public class Comment {
@Id
Long id;
String who;
String txt;
public Comment() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getWho() {
return who;
}
public void setWho(String who) {
this.who = who;
}
public String getTxt() {
return txt;
}
public void setTxt(String txt) {
this.txt = txt;
}
}
稍后,我通过点击工具>谷歌云工具>生成端点,从类中生成了一个名为CommentEndpoint的端点
package com.example.pontuse.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.Nullable;
import com.google.api.server.spi.response.CollectionResponse;
import com.google.api.server.spi.response.ConflictException;
import com.google.api.server.spi.response.NotFoundException;
import com.google.appengine.api.datastore.Cursor;
import com.google.appengine.api.datastore.QueryResultIterator;
import com.googlecode.objectify.cmd.Query;
import static com.example.pontuse.api.OfyService.ofy;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.inject.Named;
import javax.xml.ws.Endpoint;
/** An endpoint class we are exposing */
@Api(name = "commentEndpoint", version = "v1", namespace = @ApiNamespace(ownerDomain = "api.pontuse.example.com", ownerName = "api.pontuse.example.com", packagePath=""))
public class CommentEndpoint{
// Make sure to add this endpoint to your web.xml file if this is a web application.
private static final Logger LOG = Logger.getLogger(CommentEndpoint.class.getName());
public CommentEndpoint(){
}
@ApiMethod(name = "listComment")
public CollectionResponse<Comment> listComment(@Nullable @Named("cursor") String cursorString,
@Nullable @Named("count") Integer count) {
Query<Comment> query = ofy().load().type(Comment.class);
if (count != null) query.limit(count);
if (cursorString != null && cursorString != "") {
query = query.startAt(Cursor.fromWebSafeString(cursorString));
}
LOG.info("Calling listComment method");
List<Comment> records = new ArrayList<Comment>();
QueryResultIterator<Comment> iterator = query.iterator();
int num = 0;
while (iterator.hasNext()) {
records.add(iterator.next());
if (count != null) {
num++;
if (num == count) break;
}
}
if (cursorString != null && cursorString != "") {
Cursor cursor = iterator.getCursor();
if (cursor != null) {
cursorString = cursor.toWebSafeString();
}
}
return CollectionResponse.<Comment>builder().setItems(records).setNextPageToken(cursorString).build();
}
/**
* This inserts a new <code>Comment</code> object.
* @param comment The object to be added.
* @return The object to be added.
*/
@ApiMethod(name = "insertComment")
public Comment insertComment(Comment comment) throws ConflictException{
if(comment.getId() != null)
if(findRecord(comment.getId()) != null) throw new ConflictException("Object already exists");
LOG.info("Calling insertComment method");
ofy().save().entity(comment).now();
return comment;
}
@ApiMethod (name = "updateComment")
public Comment updateComment(Comment comment) throws NotFoundException{
if(findRecord(comment.getId()) == null) throw new NotFoundException("Object does not exist");
ofy().save().entity(comment).now();
return comment;
}
@ApiMethod (name = "removeComment")
public void removeComment(@Named ("id") Long id) throws NotFoundException{
Comment record = findRecord(id);
if(record == null) throw new NotFoundException("Comment record does not exist!");
LOG.info("Calling removeComment method");
ofy().delete().entity(record).now();
}
private Comment findRecord(Long id){
return ofy().load().type(Comment.class).id(id).now();
}
}
当我尝试在我的应用程序模块中创建一个AsyncTask时,请确保Android应用程序可以与应用程序引擎后端一起工作,我需要端点成员类生成器,它应该像下面这样实例化
CommentEndpoint.Builder builder = new CommentEndpoint.Builder(AndroidHttp.newCompatibleTransport(),
new AndroidJsonFactory(), null)
但是IDE告诉我没有CommentEndpoint.Builder这样的东西。我在谷歌上搜索了一下,但没有用,因为Android Studio现在在同一个项目中使用两个模块,而不是在应用程序引擎和Android应用程序的两个独立项目中。
我错过了什么吗?我最近刚安装了0.8.9,并开始从事一个涉及GAE的项目。 我对“未识别建筑商”也有同样的问题 为我修正的是删除了“在你的情况下”: 并重新导入它,将其更改为
import com.example.pontuse.api.commentEndpoint.CommentEndpoint;
添加依赖项时,这一定是一个错误。
希望这能有所帮助。可能您忘记了将依赖项添加到应用程序模块的build.gradle中,如前所述。 在“依赖项”下添加以下内容:
// BEGIN Google APIs
// Play Services will validate the application prior to allowing OAuth2 access.
compile(group: 'com.google.android.gms', name: 'play-services', version: '3.2.+')
// The following lines implement maven imports as defined at:
// https://code.google.com/p/google-api-java-client/wiki/Setup
// Add the Google API client library.
compile(group: 'com.google.api-client', name: 'google-api-client', version: '1.17.0-rc') {
// Exclude artifacts that the Android SDK/Runtime provides.
exclude(group: 'xpp3', module: 'xpp3')
exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
exclude(group: 'junit', module: 'junit')
exclude(group: 'com.google.android', module: 'android')
}
// Add the Android extensions for the Google API client library.
// This will automatically include play services as long as you have download that library
// from the Android SDK manager.
// Add the Android extensions for the Google API client library.
compile(group: 'com.google.api-client', name: 'google-api-client-android',
version: '1.17.0-rc')
{
// Exclude play services, since we're not using this yet.
exclude(group: 'com.google.android.google-play-services', module: 'google-play-services')
}
// END Google APIs
// The following client libraries make HTTP/JSON on Android easier.
// Android extensions for Google HTTP Client.
compile(group: 'com.google.http-client', name: 'google-http-client-android',
version: '1.17.0-rc') {
exclude(group: 'com.google.android', module: 'android')
}
// This is used by the Google HTTP client library.
compile(group: 'com.google.guava', name: 'guava', version: '14.0.+')
然后您应该导入:
com.example.pontuse.api.commentEndpoint.commentEndpoint
,而不是com.example.pontuse.api.commentEndpoint
,我认为这可能是因为endpointn客户端库。您在gradle文件中使用过getClientLibsOnBuild吗?仅供参考-第一次在gradle同步时下载需要一段时间
阿彭金{
端点{
// downloads client libs
getClientLibsOnBuild = true
}
}
您还可以从项目文件夹手动仅生成客户端库,如下所示:
gradlew api:appengineEndpointsGetClientLibs
我在安卓工作室也遇到了同样的问题。我从实体javabean生成了端点类,但在创建
AsyncTask
时,现在是获取生成器的方法
使用像您这样的Comment
Javabean(以及相应的CommentEndpoint),我意识到构建器并不依赖于CommentEndpoint,而是依赖于自动生成的CommentApi类
换句话说,我必须在AsyncTask类中添加这两个导入:
import com.example.pontuse.api.commentApi.commentApi代码>
import com.example.pontuse.api.commentApi.model.Comment代码>
// downloads client libs
getClientLibsOnBuild = true