optimized /data/user/0/xx is now owned by the current user

遇到这个问题 就看到大概是个 权限的问题,然后直接先上百度

https://stackoverflow.com/questions/29253434/android-dexclassloader-error-optimized-data-directory-not-owned-by-current 多用户

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);}'`
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

空白的泡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值