tarek360 / Instacapture

Android library to capture screenshot from your app
694 stars 113 forks source link

Crash on OPPO R9 all time #26

Closed fingdo closed 6 years ago

fingdo commented 6 years ago
Stack trace:  
io.reactivex.exceptions.OnErrorNotImplementedException: java.lang.NoSuchFieldException: No field mView in class Landroid/view/ColorViewRootImpl; (declaration of 'android.view.ColorViewRootImpl' appears in /system/framework/framework.jar:classes2.dex)
    at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
    at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:701)
    at io.reactivex.internal.subscribers.LambdaSubscriber.onError(LambdaSubscriber.java:76)
    at io.reactivex.internal.operators.flowable.FlowableDoOnEach$DoOnEachSubscriber.onError(FlowableDoOnEach.java:111)
    at io.reactivex.internal.operators.flowable.FlowableObserveOn$BaseObserveOnSubscriber.checkTerminated(FlowableObserveOn.java:207)
    at io.reactivex.internal.operators.flowable.FlowableObserveOn$ObserveOnSubscriber.runAsync(FlowableObserveOn.java:392)
    at io.reactivex.internal.operators.flowable.FlowableObserveOn$BaseObserveOnSubscriber.run(FlowableObserveOn.java:176)
    at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:109)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:179)
    at android.app.ActivityThread.main(ActivityThread.java:5739)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
Caused by: com.tarek360.instacapture.exception.ScreenCapturingFailedException: java.lang.NoSuchFieldException: No field mView in class Landroid/view/ColorViewRootImpl; (declaration of 'android.view.ColorViewRootImpl' appears in /system/framework/framework.jar:classes2.dex)
    at com.tarek360.instacapture.screenshot.FieldHelper.getFieldValue(FieldHelper.java:68)
    at com.tarek360.instacapture.screenshot.FieldHelper.getRootViews(FieldHelper.java:52)
    at com.tarek360.instacapture.screenshot.ScreenshotTaker.getScreenshotBitmap(ScreenshotTaker.java:49)
    at com.tarek360.instacapture.screenshot.ViewsBitmapObservable$2.call(ViewsBitmapObservable.java:42)
    at com.tarek360.instacapture.screenshot.ViewsBitmapObservable$2.call(ViewsBitmapObservable.java:39)
    at io.reactivex.internal.operators.flowable.FlowableFromCallable.call(FlowableFromCallable.java:49)
    at io.reactivex.internal.operators.flowable.FlowableScalarXMap.tryScalarXMapSubscribe(FlowableScalarXMap.java:54)
    at io.reactivex.internal.operators.flowable.FlowableFlatMap.subscribeActual(FlowableFlatMap.java:50)
    at io.reactivex.Flowable.subscribe(Flowable.java:12978)
    at io.reactivex.Flowable.subscribe(Flowable.java:12924)
    at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.run(FlowableSubscribeOn.java:82)
    ... 8 more
Caused by: java.lang.NoSuchFieldException: No field mView in class Landroid/view/ColorViewRootImpl; (declaration of 'android.view.ColorViewRootImpl' appears in /system/framework/framework.jar:classes2.dex)
    at java.lang.Class.getDeclaredField(Native Method)
    at com.tarek360.instacapture.screenshot.FieldHelper.getFieldValue(FieldHelper.java:64)
tarek360 commented 6 years ago

@fingdo Is that only happen when you open a specific view or dialog?

tarek360 commented 6 years ago

This snapshot should help

implementation 'com.github.tarek360:instacapture:fix~NoSuchFieldException-SNAPSHOT'

but please tell me, is that only happen when you open a specific view or dialog? or it happens with all of the views on OPPO R9?

fingdo commented 6 years ago

I had fix this bug.this bug because OPPO R9s Rom change framework.jar, mRoots haven't mView this field.the Rom is WindowManager have mViews. this is code.

ArrayList<View> views = (ArrayList<View>) getFieldValue("mViews", windowManager);
if (views != null && views.size() > 0) {
     view = views.get(0);
}
fingdo commented 6 years ago

This bug is try capture the screenshot,OPPO R9s Rom change framework.jar,this will be crash in OPPO R9s and OPPO R9s Plus.Thank you for your answer.

fingdo commented 6 years ago

I see your fix bug commit, this can prevent crash, but catch the exception and can't capture the screenshot.you can try my solution.

tarek360 commented 6 years ago

@fingdo Cool! 👍 could you create a pull request for that? or if you can't I will make it tonight.

fingdo commented 6 years ago

ok,I will pull request an hour later

fingdo commented 6 years ago

my Kotlin level just read the document.you can check the commit and optimize the code.

tarek360 commented 6 years ago

@fingdo now you can use the new release, and if the issue is fixed, feel free to close it, thanks 👍

compile "com.github.tarek360:instacapture:2.0.0"
fingdo commented 6 years ago

I will run 2.0.0 in OPPO R9s monday.