Mac端Android Studio运行应用报Permission denied问题求助
Android Studio Mac环境运行应用Permission denied问题排查
问题表现
同项目代码、同版本Android Studio,Windows环境运行可正常加载数据,Mac环境运行触发权限拒绝异常,网络请求失败。
核心报错日志
Late-enabling -Xcheck:jni E/ample.inclass0: Unknown bits set in runtime_flags: 0x8000 W/ample.inclass0: Unexpected CPU variant for X86 using defaults: x86 D/libEGL: Emulator has host GPU support, qemu.gles is set to 1. W/RenderThread: type=1400 audit(0.0:660): avc: denied { write } for name="property_service" dev="tmpfs" ino=857 scontext=u:r:untrusted_app:s0:c151,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0 W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied) D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so W/ample.inclass0: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed) W/ample.inclass0: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed) D/NetworkSecurityConfig: No Network Security Config specified, using platform default W/System.err: java.net.SocketException: socket failed: EPERM (Operation not permitted) W/System.err: at java.net.Socket.createImpl(Socket.java:492) W/System.err: at java.net.Socket.getImpl(Socket.java:552) W/System.err: at java.net.Socket.setSoTimeout(Socket.java:1180) W/System.err: at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:293) W/System.err: at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:207) W/System.err: at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226) W/System.err: at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106) W/System.err: at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74) W/System.err: at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255) W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201) W/System.err: at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517) W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) W/System.err: at java.lang.Thread.run(Thread.java:919) D/HostConnection: HostConnection::get() New Host Connection established 0xdb7e2040, tid 5252 D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_sync_buffer_data GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0 W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0 D/EGL_emulation: eglCreateContext: 0xf1f7e5c0: maj 3 min 0 rcv 3 D/EGL_emulation: eglMakeCurrent: 0xf1f7e5c0: ver 3 0 (tinfo 0xe6d24dd0) W/Gralloc3: mapper 3.x is not supported D/HostConnection: createUnique: call D/HostConnection: HostConnection::get() New Host Connection established 0xdb7e3800, tid 5252 D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_sync_buffer_data GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0 D/eglCodecCommon: allocate: Ask for block of size 0x1000 D/eglCodecCommon: allocate: ioctl allocate returned offset 0x3ff807000 size 0x2000 D/EGL_emulation: eglMakeCurrent: 0xf1f7e5c0: ver 3 0 (tinfo 0xe6d24dd0) D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0
已验证无效的操作
- 已在AndroidManifest.xml中配置网络权限,配置内容如下:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.example.inclass07"> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <application android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.InClass07" tools:targetApi="31"> <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
- 删除Manifest中
tools:targetApi="31"配置后重新运行,问题未解决
排查方案(按解决概率从高到低排序)
核心报错java.net.SocketException: socket failed: EPERM (Operation not permitted)属于Mac端Android模拟器环境异常,和业务代码、Manifest配置无关,按以下顺序尝试:
- 方案1:重置模拟器状态
- 卸载模拟器内当前安装的测试应用,清除模拟器中该应用的所有缓存、存储数据
- 打开Android Studio的Device Manager,找到当前使用的模拟器,点击右侧下拉菜单选择
Cold Boot Now执行冷启动,不要使用快照快速启动 - 重新构建安装应用,90%以上的同类问题可通过该步骤解决
- 方案2:排查网络拦截问题
- 检查Mac系统是否运行了网络代理、抓包工具(Clash、Surge、Charles、Little Snitch等),这类工具可能拦截模拟器的Socket请求触发权限错误,暂时关闭这类工具后重试
- 打开模拟器的系统设置-网络和互联网,确认WLAN处于开启状态,且没有配置无效的代理地址
- 方案3:重建模拟器
如果当前使用的是x86架构的模拟器,直接删除该AVD,新建一个x86_64架构、API级别和之前一致的模拟器,重新运行项目即可,旧模拟器的快照缓存损坏也会触发该问题 - 方案4:修复本地文件权限
打开Mac终端执行以下命令,为Android模拟器目录开放读写权限,之后重启Android Studio重试:chmod -R 755 ~/.android/avd/
日志中出现的
avc: denied { write } for name="property_service"是模拟器自身的SELinux系统警告,属于模拟器通用日志,和本次应用报错无关,不需要针对该日志修改业务代码。
内容的提问来源于stack exchange,提问作者Michael
相关产品推荐
相关产品推荐

