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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android/Google Play Pre-Launch Report Fails - InvocationTargetException #129

Closed
diraniac opened this issue Aug 11, 2022 · 12 comments
Closed

Comments

@diraniac
Copy link

Steps to reproduce:

  1. Use the demo: https://github.com/wi3land/ionic-appauth/tree/master/demos/angular-capacitor to create an android application in ionic
  2. Create a Google Pixel 2 virtual device in Android Studio (I'm currently running Chipmunk)
  3. Run the android application on the Google Pixel 2 virtual device
  4. Notice that the application crashes on the virtual device e.g., the login screen either does not load or gets stuck or simply causes the app to crash - the login screen gets stuck for me

Error:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at com.getcapacitor.Bridge.lambda$callPluginMethod$0$Bridge(Bridge.java:593)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at com.getcapacitor.-$$Lambda$Bridge$25SFHybyAQk7zS27hTVXh2p8tmw.run(Unknown Source:8)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at android.os.Handler.handleCallback(Handler.java:938)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at android.os.Handler.dispatchMessage(Handler.java:99)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at android.os.Looper.loopOnce(Looper.java:201)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at android.os.Looper.loop(Looper.java:288)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at android.os.HandlerThread.run(HandlerThread.java:67)
07-26 01:19:34.513: E/AndroidRuntime(9273): Caused by: java.lang.reflect.InvocationTargetException
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at java.lang.reflect.Method.invoke(Native Method)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:121)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at com.getcapacitor.Bridge.lambda$callPluginMethod$0$Bridge(Bridge.java:584)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	... 6 more
07-26 01:19:34.513: E/AndroidRuntime(9273): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://<redacted>:5002/... (has extras) }
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2087)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at android.app.Instrumentation.execStartActivity(Instrumentation.java:1747)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at android.app.Activity.startActivityForResult(Activity.java:5404)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:597)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at android.app.Activity.startActivityForResult(Activity.java:5362)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:583)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at android.app.Activity.startActivity(Activity.java:5748)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at androidx.core.content.ContextCompat.startActivity(ContextCompat.java:251)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at androidx.browser.customtabs.CustomTabsIntent.launchUrl(CustomTabsIntent.java:376)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at com.capacitorjs.plugins.browser.Browser.open(Browser.java:113)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	at com.capacitorjs.plugins.browser.BrowserPlugin.open(BrowserPlugin.java:51)
07-26 01:19:34.513: E/AndroidRuntime(9273): 	... 9 more
07-26 01:19:34.516: D/MonitoringInstr(9273): Handling an uncaught exception thrown on the thread CapacitorPlugins.
07-26 01:19:34.516: D/MonitoringInstr(9273): java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at com.getcapacitor.Bridge.lambda$callPluginMethod$0$Bridge(Bridge.java:593)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at com.getcapacitor.-$$Lambda$Bridge$25SFHybyAQk7zS27hTVXh2p8tmw.run(Unknown Source:8)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at android.os.Handler.handleCallback(Handler.java:938)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at android.os.Handler.dispatchMessage(Handler.java:99)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at android.os.Looper.loopOnce(Looper.java:201)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at android.os.Looper.loop(Looper.java:288)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at android.os.HandlerThread.run(HandlerThread.java:67)
07-26 01:19:34.516: D/MonitoringInstr(9273): Caused by: java.lang.reflect.InvocationTargetException
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at java.lang.reflect.Method.invoke(Native Method)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:121)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at com.getcapacitor.Bridge.lambda$callPluginMethod$0$Bridge(Bridge.java:584)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	... 6 more
07-26 01:19:34.516: D/MonitoringInstr(9273): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://<redacted>:5002/... (has extras) }
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2087)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at android.app.Instrumentation.execStartActivity(Instrumentation.java:1747)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at android.app.Activity.startActivityForResult(Activity.java:5404)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:597)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at android.app.Activity.startActivityForResult(Activity.java:5362)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:583)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at android.app.Activity.startActivity(Activity.java:5748)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at androidx.core.content.ContextCompat.startActivity(ContextCompat.java:251)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at androidx.browser.customtabs.CustomTabsIntent.launchUrl(CustomTabsIntent.java:376)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at com.capacitorjs.plugins.browser.Browser.open(Browser.java:113)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	at com.capacitorjs.plugins.browser.BrowserPlugin.open(BrowserPlugin.java:51)
07-26 01:19:34.516: D/MonitoringInstr(9273): 	... 9 more
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): An unhandled exception was thrown by the app.
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at com.getcapacitor.Bridge.lambda$callPluginMethod$0$Bridge(Bridge.java:593)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at com.getcapacitor.-$$Lambda$Bridge$25SFHybyAQk7zS27hTVXh2p8tmw.run(Unknown Source:8)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at android.os.Handler.handleCallback(Handler.java:938)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at android.os.Handler.dispatchMessage(Handler.java:99)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at android.os.Looper.loopOnce(Looper.java:201)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at android.os.Looper.loop(Looper.java:288)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at android.os.HandlerThread.run(HandlerThread.java:67)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): Caused by: java.lang.reflect.InvocationTargetException
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at java.lang.reflect.Method.invoke(Native Method)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:121)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at com.getcapacitor.Bridge.lambda$callPluginMethod$0$Bridge(Bridge.java:584)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	... 6 more
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://<redacted>:5002/... (has extras) }
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2087)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at android.app.Instrumentation.execStartActivity(Instrumentation.java:1747)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at android.app.Activity.startActivityForResult(Activity.java:5404)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:597)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at android.app.Activity.startActivityForResult(Activity.java:5362)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:583)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at android.app.Activity.startActivity(Activity.java:5748)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at androidx.core.content.ContextCompat.startActivity(ContextCompat.java:251)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at androidx.browser.customtabs.CustomTabsIntent.launchUrl(CustomTabsIntent.java:376)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at com.capacitorjs.plugins.browser.Browser.open(Browser.java:113)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	at com.capacitorjs.plugins.browser.BrowserPlugin.open(BrowserPlugin.java:51)
07-26 01:19:34.516: W/AndroidJUnitRunner(9273): 	... 9 more

the core exception in the full logcat.txt file is: Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://...:5002/... ionic-appauth uses this intent to open a window to show the login, is there an update to deal with this for Android 12?

The app seems to work on newer android devices like Samsung 10 I use for testing; but, the issue is with the Google Pixel 2 which has to function to pass Google Play's deployment rollout pre-tests.
I believe https://developer.android.com/about/versions/12/behavior-changes-12 may have something to do with this issue. I think this https://stackoverflow.com/questions/68554294/androidexported-needs-to-be-explicitly-specified-for-activity-apps-targeting will help solve a part of the issue. I do think it has something to do with the intent-filter found in the AndroidManifest.xml.

image

Virtual Device specifications

Model name Pixel 2 (virtual)

Manufacturer Google

Android version Android 12 (SDK 31)

Locale en_GB

Screen size 1080 x 1920

Screen density (DPI) 420

ABI x86_64

Full log:
logcat (2).txt

Any help would be much appreciated!

@mrogunlana
Copy link

I have a $2000 bounty on the first person to resolve this issue

@mraible
Copy link
Collaborator

mraible commented Aug 25, 2022

Which web framework are you using with Ionic? Angular, React, or Vue?

@mraible
Copy link
Collaborator

mraible commented Aug 25, 2022

Screen Shot 2022-08-24 at 22 12 11

I just tried Vue with Capacitor and got everything works with Pixel 2 API 31. See #131 for the changes I made.

@mrogunlana
Copy link

The app is running angular with Capacitor, here is the package.json for the versions:

{
    "name": "ionic",
    "version": "2.9.0",
    "author": "ionic",
    "homepage": "https://ionic.com/",
    "scripts": {
        "ng": "ng",
        "start": "ng serve",
        "build": "ng build",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e",
        "capacitor-resources-android": "capacitor-resources -p android",
        "capacitor-resources-ios": "capacitor-resources -p ios",
        "cordova-resources-android": "npx cordova-res android --skip-config --copy",
        "cordova-resources-ios": "npx cordova-res ios --skip-config --copy"
    },
    "private": true,
    "dependencies": {
        "@angular/common": "12.1.3",
        "@angular/core": "12.1.3",
        "@angular/forms": "12.1.3",
        "@angular/platform-browser": "12.1.3",
        "@angular/platform-browser-dynamic": "12.1.3",
        "@angular/router": "12.1.3",
        "@capacitor/android": "3.1.2",
        "@capacitor/app": "^1.0.2",
        "@capacitor/browser": "^1.0.2",
        "@capacitor/core": "3.1.2",
        "@capacitor/device": "^1.0.5",
        "@capacitor/ios": "3.1.2",
        "@capacitor/push-notifications": "^1.0.6",
        "@capacitor/splash-screen": "^1.1.5",
        "@capacitor/storage": "^1.2.2",
        "@ionic-native/app-minimize": "5.34.0",
        "@ionic-native/core": "5.34.0",
        "@ionic-native/http": "5.34.0",
        "@ionic-native/in-app-browser": "5.34.0",
        "@ionic-native/safari-view-controller": "5.34.0",
        "@ionic-native/secure-storage": "5.34.0",
        "@ionic-native/splash-screen": " 5.34.0",
        "@ionic-native/status-bar": " 5.34.0",
        "@ionic/angular": "5.6.12",
        "@ionic/storage": "^3.0.6",
        "@openid/appauth": "1.3.1",
        "axios": "^0.21.1",
        "capacitor-secure-storage-plugin": "0.6.2",
        "cordova-plugin-androidx": "^3.0.0",
        "cordova-plugin-androidx-adapter": "^1.1.3",
        "cordova-plugin-appminimize": "^1.0.1",
        "cordova-plugin-preview-any-file": "^0.2.9",
        "cordova-plugin-secure-storage-echo": "^5.1.1",
        "dotenv": "^8.2.0",
        "ionic-appauth": "^0.8.5",
        "rxjs": "6.6.7",
        "tslib": "2.3.0",
        "util": "^0.12.4",
        "zone.js": "0.11.4"
    },
    "devDependencies": {
        "@angular-devkit/build-angular": "12.1.3",
        "@angular/cli": "12.1.3",
        "@angular/compiler": "12.1.3",
        "@angular/compiler-cli": "12.1.3",
        "@angular/language-service": "12.1.3",
        "@capacitor/cli": "3.1.2",
        "@ionic/angular-toolkit": "4.0.0",
        "@types/jasmine": "3.8.1",
        "@types/jasminewd2": "2.0.10",
        "@types/node": "16.4.3",
        "codelyzer": "6.0.2",
        "jasmine-core": "3.8.0",
        "jasmine-spec-reporter": "7.0.0",
        "karma": "6.3.4",
        "karma-chrome-launcher": "~3.1.0",
        "karma-coverage-istanbul-reporter": "~3.0.2",
        "karma-jasmine": "4.0.1",
        "karma-jasmine-html-reporter": "^1.7.0",
        "protractor": "~7.0.0",
        "ts-node": "10.1.0",
        "tslint": "~6.1.0",
        "typescript": "4.3.5"
    },
    "description": "demo"
}

we could not reproduce the issue in the arm api 31 image, but we could reproduce the issue in the x86_64 api 31 pixel 2 image.

we narrowed down the culprit to the intent section in the AndroidManifest.xml of the generated android app:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.iak.msi">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
		android:usesCleartextTraffic="true">
        
        <activity
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
            android:name="com.iak.msi.MainActivity"
            android:label="@string/title_activity_main"
            android:theme="@style/AppTheme.NoActionBarLaunch"
            android:launchMode="singleTask"
			android:exported="true">
            
            <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" />
			</intent-filter>

        </activity>

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"></meta-data>
        </provider>
    </application>

    <!-- Permissions -->

    <uses-permission android:name="android.permission.INTERNET" />
   
</manifest>

what does the generated AndroidManifest.xml look like for the android app from the screenshot above? I wonder if it has something to do with how this file is setup?

@mraible
Copy link
Collaborator

mraible commented Aug 25, 2022

Here are the instructions I've been using in OktaDev Schematics.

Add your reverse domain name as the android:scheme in android/app/src/main/AndroidManifest.xml by adding another <intent-filter> above the existing one in the <activity> element.

<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="com.okta.dev-133337" /> 
</intent-filter>

@mrogunlana
Copy link

<data android:scheme="@string/custom_url_scheme" /> is a variable that translates to the reverse domain name e.g., the package name: com.test.app

Maybe the android:exported="true" may have something to do with this? I believe the recent changes introduced by google play in https://developer.android.com/about/versions/12/behavior-changes-12 may have something to do with this issue. I found this https://stackoverflow.com/questions/68554294/androidexported-needs-to-be-explicitly-specified-for-activity-apps-targeting but I haven't had luck.

Were you able to get the angular/capacitor x86_64 api 31 image working on android?

@mraible
Copy link
Collaborator

mraible commented Aug 25, 2022

I didn't have any issues with Angular + Capacitor on Android with this latest code. I did have to add http://localhost as a CORS origin at my identity provider to make it work. You can try the current version of this library from GitHub using the following in your package.json:

"ionic-appauth": "github:wi3land/ionic-appauth",

@mrogunlana
Copy link

thanks, I'll verify using the appauth package above - just checking that the pixel 2 image that you're running the Angular/Capacitor/Android is API 31 and x86_64 ?

@mraible
Copy link
Collaborator

mraible commented Aug 25, 2022

Yes.
Screen Shot 2022-08-25 at 11 39 38

@mrogunlana
Copy link

mrogunlana commented Sep 26, 2022

ok @mraible I was able to get this issue resolved and it was partially because of #129 (comment)

It seems the resolution was to upgrade to Ionic 6, but your suggestion to add the additional intent with the reverse domain name lookup was key.

I'd like to send you a reward for pointing me in the right direction. How can I do so?

@mraible
Copy link
Collaborator

mraible commented Sep 26, 2022

I'm glad you figured out a solution. There's no need to send a reward. Closing this issue is reward enough. :)

@mrogunlana
Copy link

Thanks @mraible. If you change your mind, let me know. Also, big thanks for all your work with keeping this library up-to-date. Keep up the great work and let me know how my team could support you in your efforts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants