java项目使用eclipse导出jar放入android项目的libs里为何不编译?


首先java项目是没有问题的,导出的jar在其它的java项目中也可以正常使用。
编写java和android项目的过程中eclipse也没有给出警告,编译和打包都通过。唯独在(虚拟机和真机)运行调试的时候出现错误:

   
  03-05 16:10:36.640: E/dalvikvm(32614): Could not find class 'com.test.Myfile', referenced from method com.example.baidu.MainActivity.onCreate
  
03-05 16:10:36.640: W/dalvikvm(32614): VFY: unable to resolve new-instance 454 (Lcom/test/Myfile;) in Lcom/example/baidu/MainActivity;
03-05 16:10:36.640: D/dalvikvm(32614): VFY: replacing opcode 0x22 at 0x0009
03-05 16:10:36.640: D/dalvikvm(32614): DexOpt: unable to opt direct call 0x0cd5 at 0x0b in Lcom/example/baidu/MainActivity;.onCreate
03-05 16:10:36.650: E/PhonePolicy(32614): Could not preload class for phone policy: com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback
03-05 16:10:36.700: D/TextLayoutCache(32614): Using debug level: 0 - Debug Enabled: 0
03-05 16:10:36.730: D/dalvikvm(32614): GC_CONCURRENT freed 143K, 78% free 706K/3075K, paused 1ms+1ms
03-05 16:10:36.730: D/dalvikvm(32614): GC_FOR_ALLOC freed 2K, 78% free 704K/3075K, paused 3ms
03-05 16:10:36.740: I/dalvikvm-heap(32614): Grow heap (frag case) to 3.819MB for 1048592-byte allocation
03-05 16:10:36.750: D/dalvikvm(32614): GC_FOR_ALLOC freed 2K, 59% free 1726K/4163K, paused 3ms
03-05 16:10:36.760: D/AndroidRuntime(32614): Shutting down VM
03-05 16:10:36.760: W/dalvikvm(32614): threadid=1: thread exiting with uncaught exception (group=0x40a601f8)
03-05 16:10:36.760: E/AndroidRuntime(32614): FATAL EXCEPTION: main
03-05 16:10:36.760: E/AndroidRuntime(32614): java.lang.NoClassDefFoundError: com.test.Myfile
03-05 16:10:36.760: E/AndroidRuntime(32614): at com.example.baidu.MainActivity.onCreate(MainActivity.java:19)
03-05 16:10:36.760: E/AndroidRuntime(32614): at android.app.Activity.performCreate(Activity.java:4465)
03-05 16:10:36.760: E/AndroidRuntime(32614): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-05 16:10:36.760: E/AndroidRuntime(32614): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-05 16:10:36.760: E/AndroidRuntime(32614): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-05 16:10:36.760: E/AndroidRuntime(32614): at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-05 16:10:36.760: E/AndroidRuntime(32614): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-05 16:10:36.760: E/AndroidRuntime(32614): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 16:10:36.760: E/AndroidRuntime(32614): at android.os.Looper.loop(Looper.java:137)
03-05 16:10:36.760: E/AndroidRuntime(32614): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-05 16:10:36.760: E/AndroidRuntime(32614): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 16:10:36.760: E/AndroidRuntime(32614): at java.lang.reflect.Method.invoke(Method.java:511)
03-05 16:10:36.760: E/AndroidRuntime(32614): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-05 16:10:36.760: E/AndroidRuntime(32614): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-05 16:10:36.760: E/AndroidRuntime(32614): at dalvik.system.NativeStart.main(Native Method)
03-05 16:10:39.360: I/Process(32614): Sending signal. PID: 32614 SIG: 9

将积分墙和spring这之类的第三方jar包放入android项目的libs文件夹就没有问题。不知道我的jar包和商业化的有何区别。
Windows 7 64 Bit,Java 1.7u5 64 Bit,Eclispe 4.2.1 64 Bit,ADT版本21.1。

Android

Nuthere 11 years, 3 months ago

你编译到真机或模拟器,需要把这个新jar也弄进去,eclipse-->右键项目-->Properties-->Java Build Path-->Order and Export -->勾上你的jar包--->ok再编译应该就好了

zzy3149 answered 11 years, 3 months ago

Your Answer