我正在開發一個最初由其他人創建的Android應用程序。這個應用程序使用GreenDao 2.0.0來存儲來自API的對象。在一些設備(如Nexus 5)上一切正常,但由於某些原因,它不適用於我的Android 4.2和4.4設備。代碼編譯,但是當我想啓動我的應用程序它崩潰,我得到以下錯誤:DaoObject上的GreenDao NoClassDefFoundError
11-04 16:26:35.951 6614-6614/com.myeggbox E/AndroidRuntime:致命例外:主 11 - 04 16:26:35.951 6614-6614/com.myeggbox E/AndroidRuntime:進程:com.myeggbox,PID:6614 ** 11-04 16:26:35.951 6614-6614/com.myeggbox E/AndroidRuntime:java。 lang.NoClassDefFoundError:com.myeggbox.api.data.entity.AddressDao
我之前從未使用過GreenDao,所以我迷路了,如果有人有任何想法......在我的build.gradle中,targetSdk是22,minSdkVersion是16. 這是我的EntityGenerator.java:
public static void main(String[] args) throws Exception {
Schema schema = new Schema(4, "com.myeggbox.api.data.entity");
schema.enableKeepSectionsByDefault();
//on init les Entity puis on les maps
createEntities(schema);
mapEntities();
addRelationShip();
new DaoGenerator().generateAll(schema, "../app/src/main/java/");
}
/*
** Init
*/
private static void createEntities(final Schema schema) {
address = schema.addEntity("Address");
brand = schema.addEntity("Brand");
category = schema.addEntity("Category");
code = schema.addEntity("Code");
document = schema.addEntity("Document");
egg = schema.addEntity("Egg");
product = schema.addEntity("Product");
review = schema.addEntity("Review");
service = schema.addEntity("Service");
user = schema.addEntity("User");
store = schema.addEntity("Store");
}
private static void mapEntities() {
addEgg();
addCategory();
addCode();
addDocument();
addProduct();
addStore();
addBrand();
addService();
addAddress();
addReview();
addUser();
}
private static void addRelationShip() {
//egg <-> user
Property egg_user_id = egg.addLongProperty("user_id").getProperty();
egg.addToOne(user, egg_user_id).setName("userDb");//liaison vers l'utilisateur
user.addToMany(egg, egg_user_id).setName("eggListDb");//liaison inverse
//egg <-> product
Property egg_product_id = egg.addLongProperty("product_id").getProperty();
egg.addToOne(product, egg_product_id).setName("productDb");//liaison vers le product
product.addToMany(egg, egg_product_id).setName("eggListDb");//liaison inverse
//code <-> egg
Property code_egg_id = code.addLongProperty("egg_id_db").getProperty();
code.addToOne(egg, code_egg_id).setName("eggDb");//liaison du code vers l'egg
egg.addToMany(code, code_egg_id).setName("codeListDb");//liaison inverse
//code <-> user
Property code_user_id = code.addLongProperty("user_id").getProperty();
code.addToOne(user, code_user_id).setName("userDb");
user.addToMany(code, code_user_id).setName("codeListDb");
//documents <-> egg
Property doc_egg_id = document.addLongProperty("egg_id").getProperty();
document.addToOne(egg, doc_egg_id).setName("eggDb");//liaison vers l'egg
egg.addToMany(document, doc_egg_id).setName("documentListDb");//liaison inverse
//egg <-> store
Property egg_store_id = egg.addLongProperty("store_id").getProperty();
egg.addToOne(store, egg_store_id).setName("storeDb");//relation vers l'egg
store.addToMany(egg, egg_store_id).setName("eggListDb");//relation inverse
//product <-> brand
Property product_brand_id = product.addLongProperty("brand_id").getProperty();
product.addToOne(brand, product_brand_id).setName("brandDb");//liaison vers le product
brand.addToMany(product, product_brand_id).setName("productListDb");//liaison inverse
//product <-> category
Property product_category_id = product.addLongProperty("category_id").getProperty();
product.addToOne(category, product_category_id).setName("categoryDb");//liaison vers la category
category.addToMany(product, product_category_id).setName("productListDb");//liaison inverse
//service <-> egg
Property service_egg_id = service.addLongProperty("egg_local_id").getProperty();
service.addToOne(egg, service_egg_id);//relation vers l'egg
egg.addToMany(service, service_egg_id).setName("serviceListDb");//relation inverse
//review <-> product
Property review_product_id = review.addLongProperty("product_id").getProperty();
review.addToOne(product, review_product_id).setName("productDB");//liaison vers le product
product.addToMany(review, review_product_id).setName("reviewListDb");//liaison inverse
//address <-> user
Property address_user_id = address.addLongProperty("user_id").getProperty();
address.addToOne(user, address_user_id).setName("userDB");//liaison vers le user
user.addToMany(address, address_user_id).setName("addressListDb");//liaison inverse
}
/*
** Maping des modéles
*/
private static void addEgg() {
egg.implementsInterface("Serializable", "Comparable<Egg>");
egg.addLongProperty("localId").primaryKey().autoincrement();
egg.addStringProperty("buying_date");
egg.addLongProperty("id");
egg.addStringProperty("picture");
egg.addIntProperty("warranty_duration");
egg.addStringProperty("created_at");
egg.addStringProperty("localPicture");
}
private static void addCode() {
code.implementsInterface("Serializable");
code.addLongProperty("localId").primaryKey().autoincrement();
code.addLongProperty("id");
code.addStringProperty("digest");
}
private static void addDocument() {
document.implementsInterface("Serializable");
document.addLongProperty("localId").primaryKey().autoincrement();
document.addStringProperty("content");
document.addStringProperty("created_at");
document.addLongProperty("id");
document.addStringProperty("picture");
document.addStringProperty("preview");
document.addStringProperty("title");
document.addStringProperty("UUID");
document.addStringProperty("updated_at");
document.addStringProperty("localPath");
document.addStringProperty("type");
}
private static void addStore() {
store.implementsInterface("Serializable");
store.addLongProperty("localId").primaryKey().autoincrement();
store.addLongProperty("id");
store.addStringProperty("name");
store.addStringProperty("phone");
store.addStringProperty("email");
store.addStringProperty("website");
store.addStringProperty("street_name");
store.addStringProperty("city");
store.addStringProperty("zip_code");
store.addStringProperty("country");
store.addStringProperty("facebook_url");
store.addStringProperty("logo");
store.addStringProperty("latitude");
store.addStringProperty("longitude");
}
private static void addProduct() {
product.implementsInterface("Serializable");
product.addLongProperty("localId").primaryKey().autoincrement();
product.addLongProperty("id");
product.addStringProperty("name");
product.addStringProperty("picture");
product.addStringProperty("ean");
}
private static void addBrand() {
brand.implementsInterface("Serializable");
brand.addLongProperty("localId").primaryKey().autoincrement();
brand.addLongProperty("id");
brand.addStringProperty("name");
}
private static void addCategory() {
category.implementsInterface("Serializable");
category.addLongProperty("localId").primaryKey().autoincrement();
category.addLongProperty("id");
category.addStringProperty("image");
category.addStringProperty("name");
}
private static void addService() {
service.implementsInterface("Serializable");
service.addLongProperty("localId").primaryKey().autoincrement();
service.addLongProperty("id");
service.addStringProperty("kind");
service.addStringProperty("phone");
service.addStringProperty("title");
service.addStringProperty("web_url");
service.addStringProperty("local_path");
}
private static void addUser() {
user.implementsInterface("Serializable");
user.addLongProperty("localId").primaryKey().autoincrement();
user.addStringProperty("id");
user.addStringProperty("email");
user.addStringProperty("authentication_token");
}
private static void addAddress() {
address.implementsInterface("Serializable");
address.addLongProperty("localId").primaryKey().autoincrement();
address.addStringProperty("city");
address.addStringProperty("country");
address.addStringProperty("firstname");
address.addLongProperty("id");
address.addStringProperty("lastname");
address.addStringProperty("street_name");
address.addStringProperty("zip_code");
}
private static void addReview() {
review.implementsInterface("Serializable");
review.addLongProperty("localId").primaryKey().autoincrement();
review.addStringProperty("content");
review.addStringProperty("created_at");
review.addLongProperty("id");
review.addStringProperty("locale");
review.addIntProperty("rate");
review.addStringProperty("title");
review.addStringProperty("upload_at");
review.addIntProperty("user_id");
}
}
感謝您的幫助!
嗨,謝謝你的回答,但不幸的是我試圖像你說的那樣編譯EntityGenerator.java,但是我的4.1.1設備仍然出現錯誤。我在運行EntityGenerator時沒有遇到任何錯誤,並且生成了我的類,我檢查了它。運行應用程序時出錯,而不是EntityGenerator –
@MeganLeBerre是您的android項目的源文件夾中生成的類? – AlexS