遇到这个问题 就看到大概是个 权限的问题,然后直接先上百度
Android DexClassLoader error, ‘optimized data directory .. not owned by current user’ 查到了一个类似的错误,不过作者的代码是这样的
public void loadDex() {
String dexFile = "/sdcard/output.jar";
File jarFile = new File(dexFile);
if (jarFile.exists()) {
// Toast.makeText(getApplicationContext(), "It Worked!", Toast.LENGTH_LONG).show();
DexClassLoader cl = new DexClassLoader (jarFile.toString (), "/data/test", null, ClassLoader.getSystemClassLoader());
}
}
修改成了(出于安全考虑,Android不允许应用程序将文件加载到任何随机文件夹。相反,它应该被加载到应用程序环境。这是修改后的代码,允许我继续该项目。显示的代码是’loadDex()’方法:)
public void loadDex() {
// DEX文件
String dexFile = "/output.jar";
// DEX文件全路径
File f = new File(Environment.getExternalStorageDirectory().toString() + dexFile);
// optimized directory, the applciation and package directory
// 优化的目录
final File optimizedDexOutputPath = getDir("outdex", 0);
// The specific line(s) of code that resolved the problem is: 最重要的代码在这里,其实意思就是把他copy到另外一个文件夹,这样就安全了
// DexClassLoader to get the file and write it to the optimised directory
DexClassLoader classLoader = new DexClassLoader(f.getAbsolutePath(),
optimizedDexOutputPath.getAbsolutePath(),null, getClassLoader());
// The classpath is created for the new class
String completeClassName = "poc.example.del.mylibrary.name";
String methodToInvoke = "display";
try {
Class<?> myClass = classLoader.loadClass(completeClassName);
Object obj = (Object)myClass.newInstance();
Method m = myClass.getMethod(methodToInvoke);
String s = ""+m.invoke(obj);
makeToast(s);
}
catch (Exception e) {
e.printStackTrace();
makeToast("Something went wrong!");
}
}
但是我的不是这个问题, 我的最后还是看代码,一步一步走查 发现是 android 6.0 和 7.0 的区别
修改shell 脚本, 然后主要还是要去多学习 学习 shell脚本
ls -l /data/data/|busybox grep com.taobao.taobao
# drwxr-x--x u0_a115 u0_a115 2018-03-07 19:07 com.taobao.taobao
# drwxr-x--x 14 u0_a140 u0_a140 4096 2017-05-27 19:33 com.taobao.taobao
awk 命令
uid=`ls -l /data/data/|busybox grep $line$|busybox awk '''{i=index($3,"_a");print 10000+substr($3,i+2);}'`