datatrans / android-sdk

Accept payments on your Android apps: Our mobile SDKs support your entire payment and registration process and simplify the integration of any payment method in your mobile apps.
Other
6 stars 0 forks source link

FragmentStrictMode enabled for WrongFragmentContainerViolation reveals some violations #21

Closed drezzzik closed 8 months ago

drezzzik commented 9 months ago

Enable FragmentStrictMode with at least detectWrongFragmentContainer, it will result with following issues:

FATAL EXCEPTION: main
Process: x.y.z.debug, PID: 4765
androidx.fragment.app.strictmode.WrongFragmentContainerViolation: Attempting to add fragment b0{3181ad7} (360e18a9-c1ee-4da1-8931-3bc4e4c518a6 id=0x7f0a0204 tag=PAYMENT_METHOD_ALIAS_SELECTION) to container android.widget.FrameLayout{4f09110 V.E...... ......ID 0,154-1080,154 #7f0a0204 app:id/container} which is not a FragmentContainerView
    at androidx.fragment.app.strictmode.FragmentStrictMode.onWrongFragmentContainer(FragmentStrictMode.kt:204)
    at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:519)
    at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261)
    at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1899)
    at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1817)
    at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1760)
    at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:547)

FATAL EXCEPTION: main
Process: x.y.z.debug, PID: 18467
androidx.fragment.app.strictmode.WrongFragmentContainerViolation: Attempting to add fragment d{d640e8e} (7d1fbf52-c97c-460f-a7bb-7bb186d164dd id=0x7f0a0205 tag=CREDIT_CARD) to container android.widget.FrameLayout{216ab7a V.E...... ......ID 0,147-1080,147 #7f0a0205 app:id/container} which is not a FragmentContainerView
    at androidx.fragment.app.strictmode.FragmentStrictMode.onWrongFragmentContainer(FragmentStrictMode.kt:204)
    at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:519)
    at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261)
    at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1899)
    at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1817)
    at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1760)
    at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:547)
    at android.os.Handler.handleCallback(Handler.java:958)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:230)
    at android.os.Looper.loop(Looper.java:319)
    at android.app.ActivityThread.main(ActivityThread.java:8893)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
 ``
luiscosta commented 9 months ago

Hi @drezzzik, thank you very much for bringing this up. However, our focus is to move to Jetpack Compose in the future. In the meantime, we will stick to FrameLayout, which has been working well for years.

drezzzik commented 9 months ago

The way how the FrameLayout is used is the problem.

Since the code is not open source, I can only guess that you are using supportFragmentManager from enclosing activity. Instead, parentFragmentManager or childFragmentManager should be used.

Until it is fixed, everyone integrating this library and having FragmentStrictMode enabled with detectWrongFragmentContainer, will see this issue.

luiscosta commented 9 months ago

Hey @drezzzik,

Sorry, I think I misunderstood the problem.

Do you actually see or experience some fluke on our library, some visual effect, some bug in the flows or unexpected behaviour using it? Or, is it just this error on FragmentStrictMode you are concerned about?

drezzzik commented 9 months ago

Having such mode detectWrongFragmentContainer enabled with penaltyDeath (which I have) results in application being crashing constantly whenever such Transactions screen from your library is visited.

Problem is that I cannot exclude it from the rules with allowViolation for fragment since your code is obfuscated.

All I can do is to remove detectWrongFragmentContainer from set of violations I would like to have reported, which also prevents those checks on my code. This is a bit constraint Google gave us writing it in such manner.

luiscosta commented 8 months ago

Hey @drezzzik,

This will be changed on next release 3.5.0.

drezzzik commented 8 months ago

Thanks.