Android Emulator throws Permission Denied

I test my application locally using Espresso with an Android API 22 emulator and it works. I have this in my Manifest.xml:

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

I also ask for permissions at runtime, as required after Android 23. However when Travis CI is running the tests with a same API emulator, the app throws an error:

02:10:29 V/InstrumentationResultParser: Caused by: java.io.FileNotFoundException: /storage/sdcard/dd3c49bc-efdb-41b9-90af-e814ca17c59d.png: open failed: EACCES (Permission denied)

This is my .travis.yml:

    language: android
    jdk: oraclejdk8
    sudo: false

    android:
      components:
        - tools
        - platform-tools
        - build-tools-28.0.3
        - android-28
        - android-22
        - extra-google-google_play_services
        - extra-google-m2repository
        - extra-android-m2repository
        - sys-img-armeabi-v7a-android-22

    before_script:
      - touch local.properties
      - chmod +x gradlew
      - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a
      - emulator -avd test -no-audio -no-window &
      - android-wait-for-emulator
      - adb shell input keyevent 82 &

    script:
     - ./gradlew clean build connectedCheck

I also opened a question in StackOverFlow with this problem: EACCES (Permission denied) in Travis CI Android Emulator - Stack Overflow

This is the repo Travis is building: Travis CI - Test and Deploy with Confidence

Does the process have the permissions to write to this directory?

Hi, thanks for your interest in helping me. I don’t know the answer. I’m just doing what the official documentation for building android projects says: Building an Android Project. How can i check if it has the permissions? I would not expect the need for that since this is a virtual device. The error is being thrown inside the emulator

I’m sorry, but I don’t know the inner workings of the Android emulator to offer more details. If you would like to have an interactive debug session to troubleshoot further, we are happy to enable the feature for you. https://docs.travis-ci.com/user/running-build-in-debug-mode/#enabling-debug-mode

Please email us at support@travis-ci.com. Thanks.

Somebody in StackOverFlow finally helped me to make it work: https://stackoverflow.com/questions/53624376/eacces-permission-denied-in-travis-ci-android-emulator

The thing was that Android Studio adds an aditional parameter (-c 1000M) to create a SDCard when creating an emulator, that’s why in my PC the tests ran successfully. When i added that parameter in the Travis CI commands it worked! Maybe you could add that extra parameter to the Travis CI Page, where you show an example of creating an emulator, because i think most of the people will assume that it will include a SDCard. In my case i just assigned a 100 MB SDCard (-c 100M). This is my final .travis.yml: https://github.com/GabrielBB/Android-CutOut/blob/master/.travis.yml

Oh, whoa! That’s SUPER nice! Do you mind opening a docs PR so others can benefit from this useful tip?

Thank YOU!

You welcome. Done: https://github.com/travis-ci/docs-travis-ci-com/pull/2190

1 Like