안드로이드 개발

java.lang.SecurityException: Permission denied (missing INTERNET permission?) 해결방법

피커 2022. 12. 28. 12:44
728x90
반응형

안드로이드 앱 개발 중 네트워크를 사용하다보면 아래처럼 구체적으로 permission에러가 발생하는 경우가 발생한다.

이럴때는 AndroidManifest.xml에 퍼미션 한줄만 추가하면 문제가 해결된다.

 

1. 에러 원인

  -. 인터넷을 사용하는 퍼미션없이 앱에서 인터넷 사용 요청을 할 경우 안드로이드 OS에서 거부하게된다.

 

2. 해결 방법

  -. AndroidManifest.xml파일을 열어 아래 파란색처럼 한 줄 추가해준다.

<uses-permission android:name="android.permission.INTERNET"/>

 

3. 에러문구

Error log
FATAL EXCEPTION: Thread-4
Process: com.picker.testapp, PID: 6624
java.lang.SecurityException: Permission denied (missing INTERNET permission?)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:150)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
at java.net.InetAddress.getAllByName(InetAddress.java:1152)
at com.android.okhttp.Dns$1.lookup(Dns.java:41)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:178)
at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:144)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:86)
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:176)
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128)
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:542)
at com.picker.testapp.MainActivity.sendGet(MainActivity.kt:32)
at com.picker.testapp.MainActivity$ThreadClass.run(MainActivity.kt:22)
Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
at libcore.io.Linux.android_getaddrinfo(Native Method)
at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:73)
at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:202)
at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:73)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103) 
at java.net.InetAddress.getAllByName(InetAddress.java:1152) 
at com.android.okhttp.Dns$1.lookup(Dns.java:41) 
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:178) 
at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:144) 
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:86) 
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:176) 
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128) 
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97) 
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289) 
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232) 
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465) 
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411) 
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:542) 
at com.picker.testapp.MainActivity.sendGet(MainActivity.kt:32) 
at com.picker.testapp.MainActivity$ThreadClass.run(MainActivity.kt:22) 
Caused by: android.system.ErrnoException: android_getaddrinfo failed: EPERM (Operation not permitted)
at libcore.io.Linux.android_getaddrinfo(Native Method) 
at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:73) 
at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:202) 
at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:73) 
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135) 
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103) 
at java.net.InetAddress.getAllByName(InetAddress.java:1152) 
at com.android.okhttp.Dns$1.lookup(Dns.java:41) 
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:178) 
at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:144) 
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:86) 
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:176) 
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128) 
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97) 
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289) 
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232) 
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465) 
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411) 
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:542) 
at com.picker.testapp.MainActivity.sendGet(MainActivity.kt:32) 
at com.picker.testapp.MainActivity$ThreadClass.run(MainActivity.kt:22) 
반응형