文章目录
- 一、报错信息
- 二、解决方案
一、报错信息
在 Android 应用中 , 使用 7zr 可执行程序进行压缩 , 解压缩操作 ;
代码语言:javascript复制2021-04-29 21:15:52.762 29422-29422/kim.hsl.a7_zip E/AndroidRuntime: FATAL EXCEPTION: main
Process: kim.hsl.a7_zip, PID: 29422
java.lang.RuntimeException: Unable to start activity ComponentInfo{kim.hsl.a7_zip/kim.hsl.a7_zip.MainActivity}: java.io.IOException: Cannot run program "/data/user/0/kim.hsl.a7_zip/files/7zr": error=13, Permission denied
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2951)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.io.IOException: Cannot run program "/data/user/0/kim.hsl.a7_zip/files/7zr": error=13, Permission denied
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1050)
at java.lang.Runtime.exec(Runtime.java:695)
at java.lang.Runtime.exec(Runtime.java:525)
at java.lang.Runtime.exec(Runtime.java:422)
at kim.hsl.a7_zip.MainActivity.compress7z(MainActivity.kt:88)
at kim.hsl.a7_zip.MainActivity.onCreate(MainActivity.kt:20)
at android.app.Activity.performCreate(Activity.java:7144)
at android.app.Activity.performCreate(Activity.java:7135)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2931)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.io.IOException: error=13, Permission denied
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:133)
at java.lang.ProcessImpl.start(ProcessImpl.java:132)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
at java.lang.Runtime.exec(Runtime.java:695)
at java.lang.Runtime.exec(Runtime.java:525)
at java.lang.Runtime.exec(Runtime.java:422)
at kim.hsl.a7_zip.MainActivity.compress7z(MainActivity.kt:88)
at kim.hsl.a7_zip.MainActivity.onCreate(MainActivity.kt:20)
at android.app.Activity.performCreate(Activity.java:7144)
at android.app.Activity.performCreate(Activity.java:7135)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2931)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
二、解决方案
进入 " /data/user/0/kim.hsl.a7_zip/files " 目录 , 查看文件 , 执行 " ls -la " 查看文件的详细信息 , 发现 7zr 文件的权限只有读写权限 , 没有 x 可执行权限 ;
代码语言:javascript复制C:Usersoctop>adb shell
walleye:/ $ su
walleye:/ # cd /data/user/0/kim.hsl.a7_zip/files
walleye:/data/user/0/kim.hsl.a7_zip/files # ls
7zr
walleye:/data/user/0/kim.hsl.a7_zip/files # ls -la
total 992
drwxrwx--x 2 u0_a438 u0_a438 4096 2021-04-29 21:15 .
drwx------ 5 u0_a438 u0_a438 4096 2021-04-29 21:15 ..
-rw------- 1 u0_a438 u0_a438 994304 2021-04-29 21:15 7zr
walleye:/data/user/0/kim.hsl.a7_zip/files #
调用 File 的 setExecutable(true) 方法 , 为该文件设置可执行权限 ;
代码语言:javascript复制 // /data/user/0/kim.hsl.a7_zip/files/7zr
var exeFile = File(filesDir, "7zr")
// 执行前赋予可执行权限
exeFile.setExecutable(true)