我正在使用最初由其他人创建的Android应用。这个应用程序使用GreenDao 2.0.0来存储API中的对象。在某些设备(如Nexus 5)上一切正常,但由于某些原因,它无法在我的Android 4.2和4.4设备上运行。代码编译,但当我想启动我的应用程序时崩溃,我收到以下错误:
11-04 16:26:35.951 6614-6614 / com.myeggbox E / AndroidRuntime:FATAL EXCEPTION:main 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");
}
}
感谢您的帮助!
答案 0 :(得分:1)
这不是Android类,它不应该作为Android的一部分运行。