android.system.ErrnoException:ioctl失败:EBADF(错误文件描述符)与数据/数据文件夹中的文件

时间:2018-11-16 11:01:18

标签: android file storage internal-storage android-internal-storage

我将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$1.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$2(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$5.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$1.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.access$201(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

同时,同一应用程序可以在不同设备上运行,没有例外。我在根设备上进行了检查,即使发生此异常,data/data/packagename/files文件夹中也存在zip文件。异常所指向的代码如下(与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库的抽象类。此错误的原因是什么?

PS ,我还尝试安装此应用程序的apk,该应用程序是在另一台计算机上构建的(我是在计算机上使用adb安装的),这些文件的使用没有任何重大变化,并且在没有发生此异常的相同设备上无例外地运行...因此它使我更加困惑...

PSS ,当我使用终端和gradlew任务而不是 Run 按钮在Android Studio中构建相同的应用程序时,此应用程序无需使用错误。所以这似乎与我的Android Studio有关,但是我什至无法想象到底是什么,这真让我大吃一惊...

1 个答案:

答案 0 :(得分:0)

令人难以置信,但这是因为运行/调试配置中已启用的复选框:“ 启用高级配置文件(仅API级别<26必需) ”。它解释了为什么在某些设备上所有设备都能正常工作-因为它可以在具有Android 8.0的设备上正常工作-即API26。但是此复选框如何与Android文件系统(尤其是内部存储设备)连接,我仍然不了解...