AndroidStudio / gradle找不到javax.persistence包

时间:2014-12-10 21:35:11

标签: android gradle android-studio android-gradle google-cloud-endpoints

尝试执行以下教程时:

https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial/

使用Android Studio,我创建了一个Android Studio项目并添加了CheckIn.java类,其中包含以下内容:

import java.util.Date;
import com.google.appengine.api.datastore.Key;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class CheckIn {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private java.security.Key key;
private String placeId;
private String userEmail;
private Date checkinDate;

public java.security.Key getKey() {
    return key;
}

public String getPlaceId() {
    return placeId;
}
public void setPlaceId(String placeId) {
    this.placeId = placeId;
}

public String getUserEmail() {
    return userEmail;
}
public void setUserEmail(String userEmail) {
    this.userEmail = userEmail;
}

public Date getCheckinDate() {
    return checkinDate;
}
public void setCheckinDate(Date date) {
    checkinDate = date;
}

}

但是当我尝试在我的Android Studion / gradle项目中构建项目时,我收到以下错误:

Error:(6, 25) error: package javax.persistence does not exist
Error:(7, 25) error: package javax.persistence does not exist
Error:(8, 25) error: package javax.persistence does not exist
Error:(9, 25) error: package javax.persistence does not exist
Error:(11, 2) error: cannot find symbol class Entity
Error:(14, 6) error: cannot find symbol class Id
Error:(15, 6) error: cannot find symbol class GeneratedValue
Error:(6, 25) error: package javax.persistence does not exist
Error:(7, 25) error: package javax.persistence does not exist
Error:(8, 25) error: package javax.persistence does not exist
Error:(9, 25) error: package javax.persistence does not exist
Error:(11, 2) error: cannot find symbol class Entity
Error:(14, 6) error: cannot find symbol class Id
Error:(15, 6) error: cannot find symbol class GeneratedValue

1 个答案:

答案 0 :(得分:4)

当我补充说:

compile group: 'javax.persistence', name: 'persistence-api', version: '1.0'

到我的gradle依赖项。如上所述here