android.system.ErrnoException:ioctl 失败:EBADF(错误的文件描述符)来自 data/data 文件夹的文件

android.system.ErrnoException: ioctl failed: EBADF (Bad file descriptor) with file from data/data folder

我将 Android Studio 中的同一个应用程序安装到不同的设备上,它已成功安装在所有设备上,但启动后,当我在某些设备上处理此应用程序内部存储中的文件时,出现以下错误:

E/java: [FileUploader] java.io.IOException: ioctl failed: EBADF (Bad file descriptor)
        at libcore.io.IoBridge.available(IoBridge.java:74)
        at java.io.FileInputStream.available(FileInputStream.java:108)
        at packagename.FileUploader.contentLength(FileUploader.java:530)
        at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:67)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at com.android.tools.profiler.agent.okhttp.OkHttp3Interceptor.intercept(OkHttp3Interceptor.java:57)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
        at okhttp3.RealCall.execute(RealCall.java:77)
        at packagename.performFileUploadRequest(FileUploader.java:483)
        at packagename.FileUploader.performUploadRequestByType(FileUploader.java:429)
        at com


11-16 11:45:03.138 20253-21432/packagename E/java: .packagename.FileUploader.tryUploadFileToServer(FileUploader.java:393)
        at packagename.FileUploader.lambda$uploadFileToServer(FileUploader.java:302)
        at packagename.-$$Lambda$FileUploader$MZ_TG9wHD8CqIUeh0jeiS8COakc.call(lambda)
        at rx.Observable.unsafeSubscribe(Observable.java:10256)
        at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:248)
        at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:148)
        at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:77)
        at rx.observers.Subscribers.onNext(Subscribers.java:235)
        at rx.internal.util.ScalarSynchronousObservable$WeakSingleProducer.request(ScalarSynchronousObservable.java:276)
        at rx.Subscriber.setProducer(Subscriber.java:211)
        at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102)
        at rx.Subscriber.setProducer(Subscriber.java:205)
        at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:138)
        at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:129)
        at rx.Observable.unsafeSubscribe(Observable.java:10256)
        at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:51)
        at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
        at rx.Observable.unsafeSubscribe(Observable.java:10256)
        at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
        at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
        at rx.Observable.unsafeSubscribe(Observable.java:10256)
        at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.

11-16 11:45:03.138 20253-21432/packagename E/java: java:41)
        at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
        at rx.Observable.unsafeSubscribe(Observable.java:10256)
        at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100)
        at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker.call(CachedThreadScheduler.java:230)
        at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access1(ScheduledThreadPoolExecutor.java:154)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
        at java.lang.Thread.run(Thread.java:818)
     Caused by: android.system.ErrnoException: ioctl failed: EBADF (Bad file descriptor)
        at libcore.io.Posix.ioctlInt(Native Method)
        at libcore.io.ForwardingOs.ioctlInt(ForwardingOs.java:103)
        at libcore.io.IoBridge.available(IoBridge.java:58)
            ... 60 more

同时同一个应用程序在不同的设备上工作,没有这个例外。我在根设备上检查过它,即使发生此异常,zip 文件也存在于 data/data/packagename/files 文件夹中。异常点的代码如下(符合fileStream.available()):

RequestBody requestBody = new RequestBody() {
            @Override
            public MediaType contentType() {
                return MediaType.parse(file.getMimeType());
            }

            @Override
            public long contentLength() throws IOException {
                return fileStream.available();
            }

            @Override
            public void writeTo(BufferedSink sink) throws IOException {
                Source source = null;
                try {
                    source = Okio.source(fileStream);
                    sink.writeAll(source);
                } finally {
                    Util.closeQuietly(source);
                }
            }
        };

其中 RequestBody 是来自 okhttp3 库的抽象 class。这个错误的原因是什么?

P.S. 我也尝试安装此应用程序的 apk,它是在其他计算机上构建的(我在我的计算机上使用 adb 安装它),但没有使用这些文件没有任何重大变化,并且它在之前发生此异常的相同设备上无一例外地运行......所以它让我更加困惑......

P.S.S. 当我在 Android Studio 中使用终端和 gradlew 任务构建相同的应用程序时,比 运行 按钮,这个应用程序没有这个错误。所以这似乎与我的 Android 工作室有关,但我什至无法想象到底是什么,这让我大吃一惊...

难以置信,但原因是 Run/Debug 配置中的启用复选框:“启用高级分析([API 仅限 < 26 级)”。它解释了为什么在某些设备上一切正常 - 因为它在 Android 8.0 的设备上正常工作 - 即 API 26。但是这个复选框如何与 Android 文件系统(或者,特别是内部存储),我还是不明白...