2011-02-24 13 views
9

DexClassLoader aracılığıyla harici bir kitaplık yüklemeyi deneyen bir proje üzerinde çalışıyorum. Bu 2.3 oldukça iyi çalıştı:Android'de DexClassLoader Honeycomb

02-23 09:30:58.221: ERROR/dalvikvm(8022): Can't open dex cache '/data/ 
dalvik-cache/ 
[email protected]@[email protected]@[email protected]': 
No such file or directory 
02-23 09:30:58.221: INFO/dalvikvm(8022): Unable to open or create 
cache for /data/data/at.mSystem.client/files/ 
mSystem_Client_FormularLibrary.jar (/data/dalvik-cache/ 
[email protected]@[email protected]@[email protected]) 
02-23 09:30:58.231: WARN/System.err(8022): 
java.lang.ClassNotFoundException: 
at.mSystem.client.formular.contract.ContractListFormularDisplay in 
loader [email protected] 
02-23 09:30:58.241: WARN/System.err(8022):  at 
dalvik.system.DexClassLoader.findClass(DexClassLoader.java:240) 
02-23 09:30:58.241: WARN/System.err(8022):  at 
java.lang.ClassLoader.loadClass(ClassLoader.java:548) 
02-23 09:30:58.261: WARN/System.err(8022):  at 
java.lang.ClassLoader.loadClass(ClassLoader.java:508) 
02-23 09:30:58.261: WARN/System.err(8022):  at 
at.mSystem.client.system.formularmodule.formular.FormularDisplayLoader.getDisplay(FormularDisplayLoader.java: 
35) 

: portuna Honeycomb bu uygulamayı çalışırken (bu uygulama için gerçek hedef tablet çünkü)

public class FormularDisplayLoader { 
public final static String PATH ="/data/data/at.mSystem.client/files/mSystem_Client_FormularLibrary.jar"; 
     private DexClassLoader classLoader; 

      public FormularDisplayLoader(Context context){ 
        this.context = context; 
        this.classLoader = new DexClassLoader("/data/data/at.mSystem.client/ 
    files/mSystem_Client_FormularLibrary.jar", 
         context.getFilesDir().getAbsolutePath(), 
         null, 
         FormularDisplayLoader.class.getClassLoader()); 
      } 

      public View getDisplay(String className) throws ErrorCodeException{ 
        try { 
          Class c = classLoader.loadClass(className); 
          Method m = c.getMethod("getDisplay", Context.class); 
          View ret = (View) m.invoke(c.newInstance(), context); 
          return ret; 
        } catch (Exception e) { 
          e.printStackTrace(); 
          throw new 
    ErrorCodeException(FormularErrorCode.NO_DISPLAY_AVAILABLE_FOR_FORMULAR); 
        } 
      } 

    } 

Maalesef DexClassLoader bir istisna atar DexClassLoader, benim örneğimde context.getFilesDir(). GetAbsolutePath() değeri olarak "/ data/data/ at.mSystem.client/files" değeri olarak (dexOutputDir) parametresini yoksayar.

Bunu nasıl çözeceğiniz konusunda bir fikriniz var mı? Yoksa bu bir çeşit petek böceği mi?

sayesinde değişiklik geçmişine baktığımızda

Roland

+0

Cevabım yok, ancak sadece aynı sorunu yaşadığımı bildirmek istedim. – gotosleep

+0

Android'in sorun izleyicisinde bir bilet açtım: http://code.google.com/p/android/issues/detail?id=15893 – gotosleep

+0

Dosyaya gittiğiniz aynı gün, google'dan biri "Yup, dahili hata 3439372." Honeycomb'un yaklaşan bakım sürümü için " –

cevap

2

, bu Android 3.1 ile sabit tutulmalıdır.

3

Bunun eski bir yayın olduğunu biliyorum, ancak son zamanlarda Android 3.1'e yükseltmeden buna bir yanıt verdim, bu yüzden çözümümü paylaşacağımı düşündüm.

"DexClassLoader" yerine "DexFile" sınıfını kullandım, çünkü çıktı dosyasını iletmeme izin verdi, böylece çıkış dizini yok sayılıyordu. Bu kimse yardımcı

final File dexClasses = new File("/sdcard/dexcontainer.zip"); 
DexFile dexFile = DexFile.loadDex(dexClasses.getAbsolutePath(), getFilesDir().getAbsolutePath() + "/outputdexcontainer.dex", 0); 

Enumeration<String> classFileNames = dexFile.entries(); 
while (classFileNames.hasMoreElements()) 
{ 
    String className = classFileNames.nextElement(); 
    dexFile.loadClass(className, classLoader); 
} 

Umut:

İşte benim kod.

İlgili konular