推出 SDK OTA 更新
Rolling out update of SDK OTA
我已经为 android 开发了一个 SDK applications.We 有很多客户在那里使用这个 SDK applications.Now 我已经更新了我的 SDK.I 我正在寻找一种方法更改可以反映在应用程序中,而无需更新应用程序 store.Urgent 帮助 needed.Any 帮助将提前 appreciated.Thanks。
你的情况没有这种方法。但是您可以做一件事来为下一次更新启用它。 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) { ... }
好吧,您可以使用 DexLoader class 从您的 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.");
}}
如果您需要任何帮助,请告诉我
我已经为 android 开发了一个 SDK applications.We 有很多客户在那里使用这个 SDK applications.Now 我已经更新了我的 SDK.I 我正在寻找一种方法更改可以反映在应用程序中,而无需更新应用程序 store.Urgent 帮助 needed.Any 帮助将提前 appreciated.Thanks。
你的情况没有这种方法。但是您可以做一件事来为下一次更新启用它。 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) { ... }
好吧,您可以使用 DexLoader class 从您的 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.");
}}
如果您需要任何帮助,请告诉我