2015-09-28 18 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 –