Incluya .jar en el proyecto de Android (NoClassDefFoundError - VFY:incapaz de resolver nueva instancia 812)
-
20-12-2019 - |
Pregunta
Lo que quiero: Utilice un archivo jar que contenga todas mis clases de modelo (para reutilizar en el servicio web, separé los modelos) en mi proyecto de Android.Soy nuevo en Android, así que supongo que me perdí algo.¿Es necesario exportar mis clases de manera diferente cuando lo uso en Android?
Lo que consigo:
`11-15 12:26:14.082: E/Trace(1776): error opening trace file: No such file or directory (2)
11-15 12:26:14.152: E/dalvikvm(1776): Could not find class 'ww.entities.model.User', referenced from method com.example.weightwatchersapp.MainActivity.onCreate
11-15 12:26:14.172: W/dalvikvm(1776): VFY: unable to resolve new-instance 812 (Lww/entities/model/User;) in Lcom/example/weightwatchersapp/MainActivity;
11-15 12:26:14.172: D/dalvikvm(1776): VFY: replacing opcode 0x22 at 0x000a
11-15 12:26:14.182: D/dalvikvm(1776): DexOpt: unable to opt direct call 0x1499 at 0x0c in Lcom/example/weightwatchersapp/MainActivity;.onCreate
11-15 12:26:14.212: W/System.err(1776): TEST
11-15 12:26:14.262: D/AndroidRuntime(1776): Shutting down VM
11-15 12:26:14.262: W/dalvikvm(1776): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
11-15 12:26:14.292: E/AndroidRuntime(1776): FATAL EXCEPTION: main
11-15 12:26:14.292: E/AndroidRuntime(1776): java.lang.NoClassDefFoundError: ww.entities.model.User
11-15 12:26:14.292: E/AndroidRuntime(1776): at com.example.weightwatchersapp.MainActivity.onCreate(MainActivity.java:17)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.app.Activity.performCreate(Activity.java:5104)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.os.Handler.dispatchMessage(Handler.java:99)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.os.Looper.loop(Looper.java:137)
11-15 12:26:14.292: E/AndroidRuntime(1776): at android.app.ActivityThread.main(ActivityThread.java:5041)
11-15 12:26:14.292: E/AndroidRuntime(1776): at java.lang.reflect.Method.invokeNative(Native Method)
11-15 12:26:14.292: E/AndroidRuntime(1776): at java.lang.reflect.Method.invoke(Method.java:511)
11-15 12:26:14.292: E/AndroidRuntime(1776): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-15 12:26:14.292: E/AndroidRuntime(1776): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-15 12:26:14.292: E/AndroidRuntime(1776): at dalvik.system.NativeStart.main(Native Method)`
Lo que hice:Para generarlo utilicé un proyecto java simple (no un proyecto de biblioteca o algo así y lo exporté como un jar.Puedo usar la misma biblioteca en mi proyecto Java de servicio web sin ningún problema.
Lo que probé:1.Utilice la clase MainActivity generada automáticamente y agregue el siguiente código:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.err.println("TEST");// TODO: error here
User user = new User();
user.setDailyPoints(13);
}
- Agregue entidades ww a la carpeta libs
- Haga clic derecho en la biblioteca y elija "Agregar a la ruta de compilación".
- Proyecto limpio
- Comprobado ww-entities.jar en "Pedir y exportar"
- Bibliotecas privadas de Android marcadas en "Ordenar y exportar"
Intenté seguir muchos hilos que trataban problemas similares, pero de alguna manera parece que no entiendo el punto.(No es necesario decir que soy nuevo en Android y necesito una respuesta completa para los novatos, ¿verdad?^^)
Editar:
I´m using ormlite with my models so i.e. my class User looks like:
public class User implements Serializable {
private static final long serialVersionUID = -2057474913370787753L;
@DatabaseField(generatedId = true)
private long id;
@DatabaseField(canBeNull = false, unique = true)
private String username;
@DatabaseField
private String password;
@DatabaseField
private String email;
@DatabaseField
private String forename;
@DatabaseField
private String surname;
@DatabaseField
private Date birthday;
@DatabaseField
private String sex;
@DatabaseField
private double height;
@DatabaseField
private int dailyPoints;
@DatabaseField
private int weeklyPoints;
@DatabaseField(foreign = true, foreignAutoCreate = true, foreignAutoRefresh = true)
private OnlineUserFlags onlineUserFlags;
@DatabaseField
private boolean showProfileOnline;
public User() {
}
public User(String username, String password, String email, String forename, String surname, Date birthday, String sex, double height, int dailyPoints, int weeklyPoints, OnlineUserFlags onlineUserFlags, boolean showProfileOnline) {
super();
this.username = username;
this.password = password;
this.email = email;
this.forename = forename;
this.surname = surname;
this.birthday = birthday;
this.sex = sex;
this.height = height;
this.dailyPoints = dailyPoints;
this.weeklyPoints = weeklyPoints;
this.onlineUserFlags = onlineUserFlags;
this.showProfileOnline = showProfileOnline;
}
@Override
public int hashCode() {
//generated hascode method
}
@Override
public boolean equals(Object obj) {
//generated equals method
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
//...getters/setters
}
No hay solución correcta
Otros consejos
La forma más sencilla de hacer esto (al menos en las herramientas SDK 0.22.2.1) es no exportar el archivo jar, sino agregar su ww-entities
proyecto como una dependencia de su proyecto de Android (Ruta de compilación > Proyectos).
Luego debes asegurarte de verificar ww-entities
en la pestaña Pedido y Exportación.