本帖最后由 qtfreet00 于 2017-3-8 15:25 编辑
原帖地址:http://bbs.pediy.com/thread-215078.htm
在7.0+ api 24 后,openDexFile的入参变成了5个,多了个classloader和DexPathList
[Java] 纯文本查看 复制代码 private static Object openDexFile(String sourceName, String outputName, int flags,
ClassLoader loader, DexPathList.Element[] elements) throws IOException {
// Use absolute paths to enable the use of relative paths when testing on host.
return openDexFileNative(new File(sourceName).getAbsolutePath(),
(outputName == null)
? null
: new File(outputName).getAbsolutePath(),
flags,
loader,
elements);
}
在参考基友代码后,在看雪源代码基础上加了几个判断,实现7.0+可以正常启动
[C] 纯文本查看 复制代码 if(sdk_int>22&&sdk_int<24)
{
mCookie = (*env)->GetFieldID(env, myDexFile, "mCookie", "Ljava/lang/Object;");
myOpenDexFile=(*env)->GetStaticMethodID(env, myDexFile, "openDexFile", "(Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/Object;");
}
else if(sdk_int>=24){
//7.0+ openDexFile稍有不同
mCookie = (*env)->GetFieldID(env, myDexFile, "mCookie", "Ljava/lang/Object;");
myOpenDexFile=(*env)->GetStaticMethodID(env, myDexFile, "openDexFile", "(Ljava/lang/String;Ljava/lang/String;ILjava/lang/ClassLoader;[Ldalvik/system/DexPathList$Element;)Ljava/lang/Object;");
}
[C] 纯文本查看 复制代码 if(sdk_int>22&&sdk_int<24)
{
art_MarCookie=(*env)->CallStaticObjectMethod(env, myDexFile, myOpenDexFile, inPath,0,0);
LOGI("----MarCookie:%p",art_MarCookie);
}else if(sdk_int>=24){
//7.0+此处需要5个参数
jclass ApplicationClass = (*env)->GetObjectClass(env,new_ctx);
jmethodID getClassLoader = (*env)->GetMethodID(env,ApplicationClass, "getClassLoader", "()Ljava/lang/ClassLoader;");
jobject classLoader = (*env)->CallObjectMethod(env,new_ctx, getClassLoader);
art_MarCookie=(*env)->CallStaticObjectMethod(env, myDexFile, myOpenDexFile, inPath,0,0,classLoader,0);
}
unpack.zip
(3.95 MB, 下载次数: 178)
|