capacitor-community / generic-oauth2

Generic Capacitor OAuth 2 client plugin. Stop the war in Ukraine!
MIT License
223 stars 106 forks source link

Bug: App could not be launched from APK if plugin is present #172

Closed marianapatcosta closed 2 years ago

marianapatcosta commented 2 years ago

App could not be launched on android device after successful installation of APK when the setup for intent-filter in AndroidManifest.xml referred in the docs is added

Capacitor version:

Run npx cap doctor:

Capacitor Doctor

Latest Dependencies:

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

@capacitor/cli: 3.0.1
@capacitor/core: 3.0.1
@capacitor/android: 3.0.2 @capacitor/ios: 3.1.1

Library version:

OAuth Provider:

Your Plugin Configuration

The configuration I add was only the suggested in the docs

capacitor plugins installed: @byteowls/capacitor-oauth2@3.0.1 @capacitor/app@1.0.1 @capacitor/camera@1.0.3 @capacitor/device@1.0.2 @capacitor/filesystem@1.0.2 @capacitor/geolocation@1.0.2 @capacitor/haptics@1.0.1 @capacitor/keyboard@1.0.1 @capacitor/network@1.0.2 @capacitor/share@1.0.3 @capacitor/splash-screen@1.1.0 @capacitor/status-bar@1.0.1 @capacitor/storage@1.0.3 capacitor-plugin-filesharer@1.0.0 @capacitor-community/sqlite@3.1.2

{
    // Replace this with your plugin configuration
}

Affected Platform(s):

Current Behavior

I'm using this plugin in my ionic/capacitor project and follow the setup described for Android. Everything was working great using the emulator but when I installed the .apk in my android device, the app launch icon was not on the screen, though the installation was successful and the app was listed in installed apps. In AndroiManifest.xml, I had the configuration recommended in the docs, to fix a duplication of app link after authentication with Google account:

           <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
              <data android:scheme="@string/custom_url_scheme" android:host="oauth" />
            </intent-filter>

Is there any explanation for this behaviour?

Expected Behavior

It was expected that, after the app was successfully installed, the app lauch icon would be displayed on device screen, so the app can be used.

Sample Code or Sample Application Repo

After some try/error attemptives, I notice that if I removed the configuration described for android in the documentation, the app was properly installed. In AndroiManifest.xml, I have now:

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

Reproduction Steps

Other Information

moberwasserlechner commented 2 years ago

Thanks for the task but could you include a title and the your config ;).

What other plugins do you use? Run npx cap sync android to see the list.

Could you run the app on the device from Android Studio. If I understand correctly you build a APK and move it to the device without Android Studio involved.

Could you also try to include logsEnabled in your config and look at the output.

moberwasserlechner commented 2 years ago

After looking at a AndroidManifest.xml of mine I think you chose the wrong <intent-filter> for adding the line.

Here is my main activity. com.company.project.MainActivity is a placeholder.

    <activity
      android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
      android:name="com.company.project.MainActivity"
      android:label="@string/title_activity_main"
      android:launchMode="singleTask"
      android:theme="@style/AppTheme.NoActionBarLaunch">

      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>

      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="@string/custom_url_scheme" android:host="@string/custom_host" />
      </intent-filter>

    </activity>
moberwasserlechner commented 2 years ago

see https://github.com/moberwasserlechner/capacitor-oauth2#android-default-config

marianapatcosta commented 2 years ago

Thank you for the response. I updated the my initial comment with the data you requested. As I mentioned, I've run the app using an emulator with Android Studio and everything was working as expected. Besides the configuration I've posted here, I've also tried the exact configuration for <intent-filter> that the docs mention (those you posted above) and the issue was the same. As I said, I was able to find out a solution by removing <data android:scheme="@string/custom_url_scheme" android:host="oauth" /> and the app is now working properly. I am just curious about what could be the cause of this strange behaviour, if there is any explanation for that. Thank you for your time.

moberwasserlechner commented 2 years ago

I try to give a explanation but I need some information to do so.

Could you please post your main activity from your Manifest.xml.

The docs say to put the line above in NOT in

 <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

but in

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="@string/custom_url_scheme" />
    </intent-filter>

So I need to see how it looks on your side.

marianapatcosta commented 2 years ago

Currently, I have a different configuration (the configuration that solves the issue for me). Before that, I tried two configurations in which the issue I reported occurred: this config, which was the AndroidManifest.xml generated with <data android:scheme="@string/custom_url_scheme" android:host="oauth" /> added to intent-filter `

and the exact configuration described in the docs

` Thanks.

moberwasserlechner commented 2 years ago

I don't know why it works although, you do not use both intent-filters. Like in my config above.

I would need your the content of your current AndroidManifest.xml (all of it).

If you do not want to share it, I have no way to further analyse the problem and have to close the issue.

marianapatcosta commented 2 years ago

I have no problem in sharing the file. The project is available on my github. Here is the link

moberwasserlechner commented 2 years ago

Great thx. I'll have a look.

moberwasserlechner commented 2 years ago

I'm sorry but I did not have the time to look at this in more detail. If you have any update on this, let me know. I keep the issue open for a few days but will close it then.