2015-09-28 23 views
7

我開發了一個適用於android應用程序的SDK。我們有許多客戶端在那裏使用這個SDK的應用程序。現在我已經更新了我的SDK。我正在尋找一種方式,這些更改可以反映在那裏的應用程序沒有更新那裏的應用程序在商店store.Urgent幫助needed.Any幫助將不勝感激。提前感謝。推出更新的SDK OTA

回答

4

那麼你可以動態使用DexLoader類...你可以當過你want..on存儲...以下是工作代碼更新您的SD卡裝入一個jar文件..

final String libPath = Environment.getExternalStorageDirectory() +  "/test.jar"; 
    final File tmpDir = getDir("dex", 0); 

    final DexClassLoader classloader = new DexClassLoader(libPath, tmpDir.getAbsolutePath(), null, this.getClass().getClassLoader()); 
    final Class<Object> classToLoad = (Class<Object>) classloader.loadClass("com.test.android.MainActivity"); 

    final Object myInstance = classToLoad.newInstance(); 
    final Method doSomething = classToLoad.getMethod("doSomething"); 



    doSomething.invoke(myInstance); 

,並在你的庫文件的代碼可以是這樣的

public class MainActivity { 



public void doSomething() { 

Log.e(MainActivity .class.getName(), "MainActivity : doSomething() called."); 
}} 

告訴我,如果你需要任何幫助

1

有沒有這種方式適合您的情況。但有一件事你可以做,以啓用它的下一次更新。 Android可以通過DexClassLoader動態加載編譯後的代碼。所以你編譯一個新的DEX文件,然後強制你的SDK下載並使用它。

// Internal storage where the DexClassLoader writes the optimized dex file to 
    final File optimizedDexOutputPath = getDir("outdex", Context.MODE_PRIVATE); 
    DexClassLoader cl = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(), 
             optimizedDexOutputPath.getAbsolutePath(), 
             null, 
             getClassLoader()); 
    Class libProviderClazz = null; 
    try { 
     // Load the library. 
     libProviderClazz = 
      cl.loadClass("com.example.dex.lib.LibraryProvider"); 
     // Cast the return object to the library interface so that the 
     // caller can directly invoke methods in the interface. 
     // Alternatively, the caller can invoke methods through reflection, 
     // which is more verbose. 
     LibraryInterface lib = (LibraryInterface) libProviderClazz.newInstance(); 
     lib.showAwesomeToast(this, "hello"); 
    } catch (Exception e) { ... } 
+0

你能認罪再解釋一下。我的意思是在哪裏以及如何實現這些代碼以及流程將如何實現。將這項工作通過空氣?預先感謝。 – Scorpio

+0

@HarrySharma,https://www.google.com.ua/webhp?sourceid=chrome-instant&ion=1&espv=2&es_th=1&ie=UTF-8#q=android%20dexclassloader%20example&es_th=1 –