Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidStudio / gradle cannot find javax.persistence package

While attempting to do the following tutorial :

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

using Android Studio, I created an Android Studio project and added the CheckIn.java class with the following contents :

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;
}

}

But when I try to build the project in my Android Studion / gradle project, I get the following errors :

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
like image 678
Arunabh Das Avatar asked Dec 10 '14 21:12

Arunabh Das


1 Answers

This got fixed when I added:

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

to my gradle dependencies. As described here.

like image 159
Arunabh Das Avatar answered Sep 19 '22 17:09

Arunabh Das