Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android Bug] Permission Request Crashes App When Using Embedded Capacitor 3.0 #4343

Closed
maxoertel opened this issue Mar 15, 2021 · 7 comments

Comments

@maxoertel
Copy link

Bug Report

Capacitor Version

馃拪   Capacitor Doctor  馃拪

Latest Dependencies:

  @capacitor/cli: 2.4.7
  @capacitor/core: 2.4.7
  @capacitor/android: 2.4.7
  @capacitor/ios: 2.4.7

Installed Dependencies:

  @capacitor/ios: not installed
  @capacitor/cli: 3.0.0-rc.0
  @capacitor/android: 3.0.0-rc.0
  @capacitor/core: 3.0.0-rc.0

Platform(s)

Android

Current Behavior

Hey 馃憢馃徏
I got a tab bar in my app. When the user clicks on the second tab I want to show a Capacitor BridgeFragment. This worked fine with Capacitor 2.x.x. Here is the code:

val transaction = fragmentManager.beginTransaction()
transaction.add(R.id.fragmentContainer,capacitorFragment, getFragmentTag(id))
transaction.show(capacitorFragment)
transaction.commit()

After upgrading to 3.x.x the app crashes with a IllegalStateException. StackTrace below.

Expected Behavior

The Capacitor fragment is displayed normally.

Stack Trace

    java.lang.IllegalStateException: LifecycleOwner com.xxxx.app.features.main.MainActivity@8a17bdc is attempting to register while current state is RESUMED. LifecycleOwners must call register before they are STARTED.
        at androidx.activity.result.ActivityResultRegistry.register(ActivityResultRegistry.java:120)
        at androidx.activity.ComponentActivity.registerForActivityResult(ComponentActivity.java:669)
        at androidx.activity.ComponentActivity.registerForActivityResult(ComponentActivity.java:678)
        at com.getcapacitor.Plugin.initializeActivityLaunchers(Plugin.java:133)
        at com.getcapacitor.PluginHandle.load(PluginHandle.java:96)
        at com.getcapacitor.PluginHandle.<init>(PluginHandle.java:59)
        at com.getcapacitor.Bridge.registerPlugin(Bridge.java:473)
        at com.getcapacitor.Bridge.registerAllPlugins(Bridge.java:425)
        at com.getcapacitor.Bridge.<init>(Bridge.java:168)
        at com.getcapacitor.Bridge$Builder.create(Bridge.java:1173)
        at com.getcapacitor.BridgeFragment.load(BridgeFragment.java:76)
        at com.getcapacitor.BridgeFragment.onActivityCreated(BridgeFragment.java:114)
        at com.xxxx.app.features.capacitor.presentation.WebAppFragment.onActivityCreated(WebAppFragment.kt:105)
        at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2983)
        at androidx.fragment.app.FragmentStateManager.activityCreated(FragmentStateManager.java:577)
        at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:285)
        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2177)
        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2088)
        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1990)
        at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
        at android.os.Handler.handleCallback(Handler.java:907)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:216)
        at android.app.ActivityThread.main(ActivityThread.java:7625)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

npm --version output: 6.12.1

node --version output: v12.13.1

Additional Context

When I directly add my Capacitor Fragment to my activity (not later, when the user did some action), I do not get this error.
The problem lays here:
at com.getcapacitor.Plugin.initializeActivityLaunchers(Plugin.java:133)
Capacitor tries to register something permission-related, which is not allowed at this point of the activity LifeCycle.

@fkirc
Copy link
Contributor

fkirc commented Mar 19, 2021

Thanks for reporting, I am also running into the same issue.
I guess that BridgeFragement.java is not yet prepared for Capacitor 3.X: https://github.com/ionic-team/capacitor/blob/main/android/capacitor/src/main/java/com/getcapacitor/BridgeFragment.java

I am investigating it further to find a short-term workaround.
Perhaps I will submit another PR if I find something useful.

@jcesarmobile, @carlpoole and Capacitor-team:
I know that a major release is a stressful phase, but please do not forget about the embedded users.
I am strongly convinced that a smooth experience with embedded-Capacitor will support an increased migration from native developers towards Capacitor.

@jthoms1
Copy link
Member

jthoms1 commented Mar 19, 2021

We have a separate effort underway for using Capacitor in Native applications. We will provide more info on the topic in coming months. This effort is a commercialization and will not be made available as open source. If you are interested in hearing more I am happy to chat about it!

@jthoms1 jthoms1 closed this as completed Mar 19, 2021
@fkirc
Copy link
Contributor

fkirc commented Mar 19, 2021

Thanks for the response, I think that it is important to have more clarity about this topic.

I am obviously not happy with breaking functionality that worked in Capacitor 2.X.
If this is a "won't fix"-issue, then I will be forced to cancel my migration to Capactitor 3.X.

My fear about closed-source is the ongoing maintenance of this core-functionality.
It is perfectly fine if some plugins are closed-source, but I am not so sure about core-functionality like this.

@maxoertel
Copy link
Author

maxoertel commented Mar 19, 2021

We have a separate effort underway for using Capacitor in Native applications. We will provide more info on the topic in coming months. This effort is a commercialization and will not be made available as open source. If you are interested in hearing more I am happy to chat about it!

Thanks for your reply! Does that mean intentionally BridgeFragment was kind of "deprecated" in Capacitor 3.x?
Basically it allows already embedded Capacitor, and we are very happily using it as a company. Breaking this core functionality is, as @fkirc said hard to understand for existing users.

@fkirc
Copy link
Contributor

fkirc commented Mar 19, 2021

I am already thinking about creating a permanent fork of Capacitor, with as little changes as possible to the main-repo.
The new fork could be called "embedded-capacitor" and retain full compatibility with Capacitor 3.X plugins.

The fork is now released: https://github.com/fkirc/embedded-capacitor

@fkirc
Copy link
Contributor

fkirc commented Mar 20, 2021

I appreciate you efforts for improving Capacitor over the long term, but embedded-support has been delayed multiple times.
In August 2020, embedded-support was promised for Capacitor 3.X: #3405
Now in March 2021, embedded-support is promised as a closed-source solution while breaking the already existing support at the same time.
Therefore, I have finally decided to publish embedded-capacitor: https://github.com/fkirc/embedded-capacitor.
embedded-capacitor is available on npm right now because my proposals for the main-repo have been rejected over a period of multiple months.

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 11, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants