-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API 17: java.lang.RuntimeException: Failed to create the directory for screenshots. Is your sdcard directory read-only? #162
Comments
Hmm interesting. I'll have to look into why this is happening. |
Any news yet? Or anything I can do to assist? |
Sorry, I haven't had time to look into this yet, currently swamped with other things :( . If you have the time, debugging the issue would be very helpful. I'm unsure why we dont have permission to write to external storage on API 17... |
Still haven't spent enough time debugging this, however if you can run some adb commands prior to running your tests, then you should be able to the following:
This will remount your external storage to have write capability, and should work around the issue while I try to find time to figure out whats going wrong. |
Its been a while since this task was updated, and the workaround I posted should alleviate this issue. Please comment here if it doesnt. |
Sorry this went off my radar. I've tried the workaround but I'm still getting the same exception. |
I also have this error... minSdkVersion 21 and targetSdkVersion 28, with
|
I still don’t manage to bootstrap the snapshot tests, I still get the same stack trace
I tried using the
I was reading the code of the library and seem just issues with creating the directories and cleaning the files, in The following lines fail for (String s : mDir.list()) {
new File(mDir, s).delete();
} Because
All of this seems quite weird to be honest. Have you tried to use I attach some extra code for completeness-sake
```xml
package com.schibsted.peil
import android.content.Intent
import android.widget.LinearLayout
import androidx.test.InstrumentationRegistry
import com.facebook.testing.screenshot.Screenshot
import com.facebook.testing.screenshot.Screenshot.snapActivity
import com.facebook.testing.screenshot.ViewHelpers
import com.schibsted.peil.feature.feed.FeedActivity
import com.schibsted.peil.feature.feed.FooterStoryViewHolder
import org.junit.Test
class ThirteenCardScreenshotTest {
@Test
fun testScreenshot() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val view = LinearLayout(context)
val viewHolder = FooterStoryViewHolder(view)
view.addView(viewHolder.itemView)
ViewHelpers.setupView(view)
.setExactWidthDp(360)
.setExactHeightDp(740)
.layout()
Screenshot.snap(view)
.record()
}
} |
Can we re-open this to indicate it's still a problem? I'm having the same issue and suggested workaround doesn't work |
Sure, I'm not seeing this issue locally so I'm not sure how best to help... |
this happens on emulators with API level 28 only when trying to run the tests for the first time, to reproduce:
and then simply run the test from android studio or using I also tried to add @get:Rule
var permissionRule = GrantPermissionRule.grant(
android.Manifest.permission.READ_EXTERNAL_STORAGE,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE
) to my tests, but that didn't solve the problem either |
This problem happens on Android 10 (Q), too, due to the introduction of scoped external storage. Adding |
Hi, @xiphirx this issue seems to be related to the relation between the APK generated with your test code and the APK generated with your production code. The first time you install both APKs while running the instrumentation tests from Android Studio or the command line an ID is assigned to both APKs. However, if for some reason this id is not the same for both APKs, the testing APK will not be able to access the production APK resources. This is Id can be configured in the application node declaration inside any
I don't know why the error seems to be related to the directory creation. The folder where the screenshots are being recorded is in the SD card and the permission is granted. Assigning different IDs seems to the testing APK and the production APK seems to be related but I don't fully understand why because I've got this library working in projects with the default I found the solution because a shot library user reported me this error and we created a sample project where (I don't understand why) Android generates different id's for the testing and production APKs. To fix this you can configure your testing AndoridManifest with the same id the production APK uses. You can use a special flavor or build type AndroidManiefst if you don't want to add this param to your production manifest This could be the testing manifest: <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.snapshottesting.test"
android:sharedUserId="com.example.snapshottesting.uid">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</manifest> and this the production manifest: <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.snapshottesting"
android:sharedUserId="com.example.snapshottesting.uid">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest> I'm uploading here two Android projects where you can see the error. The first one will fail when running the tests and the second one, with the same code but adding the SnapshotTesting failing.zip I hope it helps 😃 |
The issue is also present on the API 30 with the new scoped storage. I did try to fix it by using getExternalFileDirs(Environment.PICTURES) but I forgot that connectedAndroidTest removes both apk and it's scoped storage....
Calling this from the targetContext crash the process and on mContext does nothing. If someone have an alternative idea I can try to implement it. |
I did find a hack to scoped storage I'm going to open a PR within the day |
Hello Everyone, I'm having the same issues after updating my project to use API 30.
|
Same issue here. Screenshot tests were running fine on API 29 for me. Did anyone discover a workaround for this? |
Same issue here on Android emulator 30 (Android 11) |
Same issue on Android emulator API 28 without google API I tried all following possible solutions:
If I tried to grant rule in runtime I get exception that this permission can not be granted..
|
Same issue here on Android 11 API 30 |
Didn't resolve anything. This |
Same issue with API level 30.. Any solution.. seems like PR #273 also yet to be merged |
Any solution? |
Executing the screenshots with
connectedTest
fails on an emulator with SDK 17 and succeeds at SDK 21.Repro steps:
Create an emulator with SDK 17
execute
connectedCheck
task and it'll fail.When using this setup it works without any problems:
The text was updated successfully, but these errors were encountered: