-
-
[求助]尝试动态加载运行未安装APK时遇到错误,求助!
-
发表于: 2014-4-22 16:51 3392
-
Android 2.3 AVD下,尝试动态加载运行未安装APK时,执行到 最后一句 methodonCreate.invoke(instance, paramBundle) 时,报异常,
实在不明白错哪了,请大神指点!
public void LoadAPK(Bundle paramBundle, String dexpath, String dexoutputpath) {
try {
ClassLoader localClassLoader = ClassLoader.getSystemClassLoader();
DexClassLoader localDexClassLoader = new DexClassLoader(dexpath, dexoutputpath, null, localClassLoader);
//DexClassLoader localDexClassLoader = new DexClassLoader(dexpath, dexoutputpath, null, this.getClass().getClassLoader());
PackageInfo plocalObject = getPackageManager().getPackageArchiveInfo(dexpath, 1);//PackageManager.GET_ACTIVITIES);
if ((plocalObject.activities != null) && (plocalObject.activities.length > 0)) {
String activityname = plocalObject.activities[0].name;
Log.d("sys", "activityname = " + activityname);
localClass = localDexClassLoader.loadClass(activityname);
mActivityClass = localClass;
Constructor localConstructor = localClass.getConstructor(new Class[] {});
instance = localConstructor.newInstance(new Object[] {});
Log.d("sys", "instance = " + instance);
mActivityInstance = instance;
Method des = localClass.getMethod("test");
des.invoke(instance);
Method localMethodSetActivity = localClass.getDeclaredMethod("setActivity", new Class[] { Activity.class });
localMethodSetActivity.setAccessible(true);
localMethodSetActivity.invoke(instance, new Object[] { this });
Method methodonCreate = localClass.getDeclaredMethod("onCreate", new Class[] { Bundle.class });
methodonCreate.setAccessible(true);
methodonCreate.invoke(instance, paramBundle); <<<<<<<执行到此发生异常
}
} catch (Exception ex) {
ex.printStackTrace();
}
异常信息如下:
java.lang.reflect.InvocationTargetException
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:507)
com.example.loadtest.MainActivity.LoadAPK(MainActivity.java:164)
……
……
附件是源代码,想从LoadTest 启动未安装的 /mnt/sdcard/FirstDex.apk
实在不明白错哪了,请大神指点!
public void LoadAPK(Bundle paramBundle, String dexpath, String dexoutputpath) {
try {
ClassLoader localClassLoader = ClassLoader.getSystemClassLoader();
DexClassLoader localDexClassLoader = new DexClassLoader(dexpath, dexoutputpath, null, localClassLoader);
//DexClassLoader localDexClassLoader = new DexClassLoader(dexpath, dexoutputpath, null, this.getClass().getClassLoader());
PackageInfo plocalObject = getPackageManager().getPackageArchiveInfo(dexpath, 1);//PackageManager.GET_ACTIVITIES);
if ((plocalObject.activities != null) && (plocalObject.activities.length > 0)) {
String activityname = plocalObject.activities[0].name;
Log.d("sys", "activityname = " + activityname);
localClass = localDexClassLoader.loadClass(activityname);
mActivityClass = localClass;
Constructor localConstructor = localClass.getConstructor(new Class[] {});
instance = localConstructor.newInstance(new Object[] {});
Log.d("sys", "instance = " + instance);
mActivityInstance = instance;
Method des = localClass.getMethod("test");
des.invoke(instance);
Method localMethodSetActivity = localClass.getDeclaredMethod("setActivity", new Class[] { Activity.class });
localMethodSetActivity.setAccessible(true);
localMethodSetActivity.invoke(instance, new Object[] { this });
Method methodonCreate = localClass.getDeclaredMethod("onCreate", new Class[] { Bundle.class });
methodonCreate.setAccessible(true);
methodonCreate.invoke(instance, paramBundle); <<<<<<<执行到此发生异常
}
} catch (Exception ex) {
ex.printStackTrace();
}
异常信息如下:
java.lang.reflect.InvocationTargetException
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:507)
com.example.loadtest.MainActivity.LoadAPK(MainActivity.java:164)
……
……
附件是源代码,想从LoadTest 启动未安装的 /mnt/sdcard/FirstDex.apk
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)
赞赏
他的文章
谁下载
看原图
赞赏
雪币:
留言: