java.io.FileNotFoundException: /storage/emulated/0/DCIM/Camera/20201021_135624.jpg: open failed: EACCES(Permission denied)

테스트 도중 이런 에러가 발생했습니다. 파일 업로드 중에 발생했는데 이유를 알아보니 파일 생성 시 저장소에 관한 내용이었습니다.

앱을 삭제해도 앱 파일들은 삭제되지만 외부저장소에 있는 파일들은 앱 제거시 삭제가 되지 않는다는 것입니다.

즉 안드로이드는 앱을 제거해도 내부에 파일이 남기 때문에 구글은 이것을 보안하려고 하는 것 같습니다.

아직까지 이 부분에 대해서 많은 개발자들이 코드를 적용하지 못한 거 같아서 당장 없애진 않았네요 구글도 이 부분을 인지하고 아직 방법을 남겨 뒀습니다.

manifest에 requestLegacyExternalStorage 속성을 true로 해줍니다.

<application 
...
    android:requestLegacyExternalStorage="true" ... >
        

developer.android.com/training/data-storage/files/external-scoped

 

728x90

앱을 잘 만들고 있는 도중 에러가 발생했다.

network security policy 라고 하는 것 보니깐 네트워크 보안 정책이 바뀐 것 같다.

잘은 모르지만 기본적으론 HTTP 통신을 기본으로 허용했지만 결론적으로 HTTP 통신을 차단을 했습니다.

MANIFEST 속성이 하나 추가됐습니다. 바로 android:usesCleartextTraffic 입니다.

이 속성이 누가 버전부터 추가된 모양입니다. 저 속성은 기본 값이 FALSE 인듯 합니다.

 

그래서 가장 쉬운 해결방법은 API의 URL을 HTTP에서 HTTPS로 변경하면 됩니다.

사실 이게 쉬웠으면 좋겠지만 안드로이드 개발자 입장에서 쉽다고 할 수는 없겠죠...

다른 해결방법도 있습니다.

네트워크 보안 구성 파일 (newwork_security_config)을 만들어줍니다.

res/xml/network_security_config.xml

<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">insecure.example.com</domain>
        <domain includeSubdomains="true">insecure.cdn.example.com</domain>
    </domain-config>
</network-security-config>

그리고  manifest에 추가 해줍니다. 

<application
    ...
    android:networkSecurityConfig="@xml/network_security_config">

 

android-developers.googleblog.com/2018/04/protecting-users-with-tls-by-default-in.html

 

이런 방법도 있는데 정말 간단한 방법도 있더라고요. 그렇지만 공식 문서에서는 추천하지 않고 있습니다.

<application
    ...
   android:usesCleartextTraffic="true">

문제는 없었는데 보안상에는 안좋다고 나와있네요.

developer.android.com/guide/topics/manifest/application-element#usesCleartextTraffic

 

 

android-developers.googleblog.com/2018/04/protecting-users-with-tls-by-default-in.html

developer.android.com/guide/topics/manifest/application-element#usesCleartextTraffic

728x90

+ Recent posts