运行APP时dex2oat过程中无法在系统中创建文件夹

来源:互联网 发布:富木制衣淘宝旗舰店 编辑:程序博客网 时间:2024/06/08 07:55
运行APP时在dex2oat的过程中,出现如下错误:
*E dex2oat : Could not get file name restrictions for .//sdcard/1_post_parse_cfg/: No such file or directory*
经追踪查找,是在文件compiler/dex/mir_graph.cc 中函数CreateDumpFile(...)内执行以下语句时 max_name_length =  -1 导致上述错误。


  int64_t max_name_length = pathconf(dir.c_str(), _PC_NAME_MAX);
 if (max_name_length <= 0) {
    PLOG(ERROR) << "Could not get file name restrictions for " << dir;
    return false;
  }


而 max_name_length =  -1 是因为在文件系统根目录下不存在  .//sdcard/1_post_parse_cfg/ 这个目录,它也不会自动创建。
于是在上述语句之前尝试以下方法,试图创建这个目录。
1.系统函数 int system(const char * string) , 头文件 #include<stdlib.h>


    std::string dir_new = "/system/bin/mkdir -p " + dir;
    int syst = std::system(dir_new.c_str()); //create the directory
    LOG(INFO) << " HXM system:" << syst; 


2.系统函数 int mkdir(const char *pathname, mode_t mode) , 头文件 #include <sys/stat.h>  #include <sys/types.h>


    int status = mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
    LOG(INFO) << " HXM status:" << status;


3.系统函数 int execv(const char *pathname, char * const argv[]) , 头文件 #include <unistd.h>
    由于要配合fork()函数, 如果应用程序正常执行完毕,那么execv是永远不会返回的(参看: http://blog.csdn.net/west_609/article/details/5941968),故此处不宜使用此函数。


上述方法都尝试失败,因为在android系统根目录下没有权限去创建目录。最后,根据打印的日志查看缺少哪些目录,人工在系统中补上。
mkdir sdcard
mkdir -p sdcard/1_post_parse_cfg/
mkdir -p sdcard/mkdir -p sdcard/
mkdir -p sdcard/mkdir -p sdcard/
0 0
原创粉丝点击