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

[Bug]: Android live reload doesn't work, but build works fine. Error: java.lang.IllegalArgumentException: allowedOriginRules #7423

Closed
1 of 3 tasks
kimproductions opened this issue Apr 23, 2024 · 7 comments · Fixed by #7426
Labels
platform: android type: bug A confirmed bug report

Comments

@kimproductions
Copy link

Capacitor Version

💊 Capacitor Doctor 💊

Latest Dependencies:

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

Installed Dependencies:

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

[success] iOS looking great! 👌
[success] Android looking great! 👌

Other API Details

npm --version 10.5.0
node --version v21.7.3

MacOs M1 14.4.1 (23E224)
android-studio-2023.2.1.25-mac_arm
Android 14.0 API LEVEL 34
Google APIS ARM 64 v8a System Image
Android Emulator 34.1.20
Android SDK Platform tools 35.0.1
Android SDK Build tools 34.0.0
Pixel 8 API 34

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

On Android, I'm getting an error when trying to use a development server for live reloading. Not using a dev server (removing the server url options from capacitor config) works completely fine. IOS both dev server and no dev server works fine.

When running a simple react vite project, I have the vite server open in one terminal window and setup the capacitor config as so:

const config: CapacitorConfig = {
    appId: "com.example.app",
    appName: "capacitorfix",
    webDir: "dist",
    server: {
        url: "http://localhost:5173/",
    },
};

After running npm run build, npx cap sync, npx cap open android and then pressing play on the emulator, I get this error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.MainActivity}: java.lang.IllegalArgumentException: allowedOriginRules http:localhost:5173 is invalid

My suspicion is that the URL format seems a bit strange without the dashes, or it could be some cors issue.
The production build works fine just not dev server and both are working on ios for some reason.

Heres the full log:

2024-04-23 12:09:17.930 10159-10159 Compatibil...geReporter com.example.app                      D  Compat change id reported: 171979766; UID 10190; state: ENABLED
2024-04-23 12:09:17.931 10159-10159 Compatibil...geReporter com.example.app                      D  Compat change id reported: 242716250; UID 10190; state: ENABLED
2024-04-23 12:09:17.970 10159-10159 ziparchive              com.example.app                      W  Unable to open '/data/app/~~01JAqcvAAOpdPOR4eSP73A==/com.example.app-OYOTdDGUWJvbrsr48LriDw==/base.dm': No such file or directory
2024-04-23 12:09:17.970 10159-10159 ziparchive              com.example.app                      W  Unable to open '/data/app/~~01JAqcvAAOpdPOR4eSP73A==/com.example.app-OYOTdDGUWJvbrsr48LriDw==/base.dm': No such file or directory
2024-04-23 12:09:18.121 10159-10159 nativeloader            com.example.app                      D  Configuring clns-6 for other apk /data/app/~~01JAqcvAAOpdPOR4eSP73A==/com.example.app-OYOTdDGUWJvbrsr48LriDw==/base.apk. target_sdk_version=34, uses_libraries=, library_path=/data/app/~~01JAqcvAAOpdPOR4eSP73A==/com.example.app-OYOTdDGUWJvbrsr48LriDw==/lib/arm64, permitted_path=/data:/mnt/expand:/data/user/0/com.example.app
2024-04-23 12:09:18.133 10159-10159 GraphicsEnvironment     com.example.app                      V  Currently set values for:
2024-04-23 12:09:18.133 10159-10159 GraphicsEnvironment     com.example.app                      V    angle_gl_driver_selection_pkgs=[]
2024-04-23 12:09:18.133 10159-10159 GraphicsEnvironment     com.example.app                      V    angle_gl_driver_selection_values=[]
2024-04-23 12:09:18.134 10159-10159 GraphicsEnvironment     com.example.app                      V  ANGLE GameManagerService for com.example.app: false
2024-04-23 12:09:18.134 10159-10159 GraphicsEnvironment     com.example.app                      V  com.example.app is not listed in per-application setting
2024-04-23 12:09:18.134 10159-10159 GraphicsEnvironment     com.example.app                      V  Neither updatable production driver nor prerelease driver is supported.
2024-04-23 12:09:18.169 10159-10220 libEGL                  com.example.app                      D  loaded /vendor/lib64/egl/libEGL_emulation.so
2024-04-23 12:09:18.170 10159-10220 libEGL                  com.example.app                      D  loaded /vendor/lib64/egl/libGLESv1_CM_emulation.so
2024-04-23 12:09:18.171 10159-10220 libEGL                  com.example.app                      D  loaded /vendor/lib64/egl/libGLESv2_emulation.so
2024-04-23 12:09:18.190 10159-10159 AppCompatDelegate       com.example.app                      D  Checking for metadata for AppLocalesMetadataHolderService : Service not found
2024-04-23 12:09:18.265 10159-10159 com.example.app         com.example.app                      W  Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (unsupported, reflection, allowed)
2024-04-23 12:09:18.265 10159-10159 com.example.app         com.example.app                      W  Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (unsupported, reflection, allowed)
2024-04-23 12:09:18.278 10159-10159 WebViewFactory          com.example.app                      I  Loading com.google.android.webview version 113.0.5672.136 (code 567263634)
2024-04-23 12:09:18.288 10159-10159 ziparchive              com.example.app                      W  Unable to open '/data/app/~~HCHvx5HxOhd4Nh1MgLZvEA==/com.google.android.trichromelibrary_567263634-Gpbc5WARYVBhgNbLXQj69A==/TrichromeLibrary.dm': No such file or directory
2024-04-23 12:09:18.288 10159-10159 ziparchive              com.example.app                      W  Unable to open '/data/app/~~HCHvx5HxOhd4Nh1MgLZvEA==/com.google.android.trichromelibrary_567263634-Gpbc5WARYVBhgNbLXQj69A==/TrichromeLibrary.dm': No such file or directory
2024-04-23 12:09:18.289 10159-10159 com.example.app         com.example.app                      W  Entry not found
2024-04-23 12:09:18.298 10159-10159 nativeloader            com.example.app                      D  Configuring clns-7 for other apk /data/app/~~HCHvx5HxOhd4Nh1MgLZvEA==/com.google.android.trichromelibrary_567263634-Gpbc5WARYVBhgNbLXQj69A==/TrichromeLibrary.apk. target_sdk_version=34, uses_libraries=ALL, library_path=/data/app/~~FzURsttVizbFbVbb1esBSg==/com.google.android.webview-i3xdE3qZSQ0FBUx_D3yiZA==/lib/arm64:/data/app/~~FzURsttVizbFbVbb1esBSg==/com.google.android.webview-i3xdE3qZSQ0FBUx_D3yiZA==/WebViewGoogle.apk!/lib/arm64-v8a:/data/app/~~HCHvx5HxOhd4Nh1MgLZvEA==/com.google.android.trichromelibrary_567263634-Gpbc5WARYVBhgNbLXQj69A==/TrichromeLibrary.apk!/lib/arm64-v8a, permitted_path=/data:/mnt/expand
2024-04-23 12:09:18.308 10159-10159 nativeloader            com.example.app                      D  Configuring clns-8 for other apk /data/app/~~FzURsttVizbFbVbb1esBSg==/com.google.android.webview-i3xdE3qZSQ0FBUx_D3yiZA==/WebViewGoogle.apk. target_sdk_version=34, uses_libraries=, library_path=/data/app/~~FzURsttVizbFbVbb1esBSg==/com.google.android.webview-i3xdE3qZSQ0FBUx_D3yiZA==/lib/arm64:/data/app/~~FzURsttVizbFbVbb1esBSg==/com.google.android.webview-i3xdE3qZSQ0FBUx_D3yiZA==/WebViewGoogle.apk!/lib/arm64-v8a:/data/app/~~HCHvx5HxOhd4Nh1MgLZvEA==/com.google.android.trichromelibrary_567263634-Gpbc5WARYVBhgNbLXQj69A==/TrichromeLibrary.apk!/lib/arm64-v8a, permitted_path=/data:/mnt/expand
2024-04-23 12:09:18.354 10159-10159 com.example.app         com.example.app                      W  Accessing hidden method Landroid/os/Trace;->isTagEnabled(J)Z (unsupported, reflection, allowed)
2024-04-23 12:09:18.354 10159-10159 com.example.app         com.example.app                      W  Accessing hidden method Landroid/os/Trace;->traceBegin(JLjava/lang/String;)V (unsupported, reflection, allowed)
2024-04-23 12:09:18.355 10159-10159 com.example.app         com.example.app                      W  Accessing hidden method Landroid/os/Trace;->traceEnd(J)V (unsupported, reflection, allowed)
2024-04-23 12:09:18.355 10159-10159 com.example.app         com.example.app                      W  Accessing hidden method Landroid/os/Trace;->asyncTraceBegin(JLjava/lang/String;I)V (unsupported, reflection, allowed)
2024-04-23 12:09:18.355 10159-10159 com.example.app         com.example.app                      W  Accessing hidden method Landroid/os/Trace;->asyncTraceEnd(JLjava/lang/String;I)V (unsupported, reflection, allowed)
2024-04-23 12:09:18.358 10159-10159 cr_WVCFactoryProvider   com.example.app                      I  Loaded version=113.0.5672.136 minSdkVersion=29 isBundle=false multiprocess=true packageId=2
2024-04-23 12:09:18.386 10159-10159 cr_LibraryLoader        com.example.app                      I  Successfully loaded native library
2024-04-23 12:09:18.388 10159-10159 cr_CachingUmaRecorder   com.example.app                      I  Flushed 8 samples from 8 histograms.
2024-04-23 12:09:18.459 10159-10159 Compatibil...geReporter com.example.app                      D  Compat change id reported: 183155436; UID 10190; state: ENABLED
2024-04-23 12:09:18.499 10159-10236 chromium                com.example.app                      W  [WARNING:dns_config_service_android.cc(115)] Failed to read DnsConfig.
2024-04-23 12:09:18.564 10159-10246 chromium                com.example.app                      E  [ERROR:simple_file_enumerator.cc(58)] Could not get file info for /data/user/0/com.example.app/cache/WebView/Default/HTTP Cache/Code Cache/wasm/index
2024-04-23 12:09:18.565 10159-10246 chromium                com.example.app                      E  [ERROR:simple_file_enumerator.cc(21)] opendir /data/user/0/com.example.app/cache/WebView/Default/HTTP Cache/Code Cache/js: No such file or directory (2)
2024-04-23 12:09:18.565 10159-10246 chromium                com.example.app                      E  [ERROR:simple_index_file.cc(614)] Could not reconstruct index from disk
2024-04-23 12:09:18.573 10159-10159 Compatibil...geReporter com.example.app                      D  Compat change id reported: 214741472; UID 10190; state: ENABLED
2024-04-23 12:09:18.575 10159-10159 Compatibil...geReporter com.example.app                      D  Compat change id reported: 171228096; UID 10190; state: ENABLED
2024-04-23 12:09:18.599 10159-10159 Capacitor               com.example.app                      D  Starting BridgeActivity
2024-04-23 12:09:18.623 10159-10159 Capacitor               com.example.app                      D  Registering plugin instance: CapacitorCookies
2024-04-23 12:09:18.626 10159-10159 Capacitor               com.example.app                      D  Registering plugin instance: WebView
2024-04-23 12:09:18.628 10159-10159 Capacitor               com.example.app                      D  Registering plugin instance: CapacitorHttp
2024-04-23 12:09:18.643 10159-10159 Capacitor               com.example.app                      W  Unable to read file at path public/plugins
2024-04-23 12:09:18.646 10159-10159 AndroidRuntime          com.example.app                      D  Shutting down VM
2024-04-23 12:09:18.651 10159-10159 AndroidRuntime          com.example.app                      E  FATAL EXCEPTION: main
                                                                                                    Process: com.example.app, PID: 10159
                                                                                                    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.MainActivity}: java.lang.IllegalArgumentException: allowedOriginRules http:localhost:5173 is invalid
                                                                                                    	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3782)
                                                                                                    	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3922)
                                                                                                    	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:205)
                                                                                                    	at android.os.Looper.loop(Looper.java:294)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8177)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
                                                                                                    Caused by: java.lang.IllegalArgumentException: allowedOriginRules http:localhost:5173 is invalid
                                                                                                    	at J.N.MrxnMTWN(Native Method)
                                                                                                    	at Ok0.a(chromium-TrichromeWebViewGoogle6432.apk-stable-567263634:72)
                                                                                                    	at lo0.addDocumentStartJavaScript(chromium-TrichromeWebViewGoogle6432.apk-stable-567263634:10)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at lf.invoke(chromium-TrichromeWebViewGoogle6432.apk-stable-567263634:36)
                                                                                                    	at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
                                                                                                    	at $Proxy3.addDocumentStartJavaScript(Unknown Source)
                                                                                                    	at androidx.webkit.internal.WebViewProviderAdapter.addDocumentStartJavaScript(WebViewProviderAdapter.java:110)
                                                                                                    	at androidx.webkit.WebViewCompat.addDocumentStartJavaScript(WebViewCompat.java:823)
                                                                                                    	at com.getcapacitor.Bridge.loadWebView(Bridge.java:262)
                                                                                                    	at com.getcapacitor.Bridge.<init>(Bridge.java:223)
                                                                                                    	at com.getcapacitor.Bridge.<init>(Unknown Source:0)
                                                                                                    	at com.getcapacitor.Bridge$Builder.create(Bridge.java:1555)
                                                                                                    	at com.getcapacitor.BridgeActivity.load(BridgeActivity.java:48)
                                                                                                    	at com.getcapacitor.BridgeActivity.onCreate(BridgeActivity.java:42)
                                                                                                    	at android.app.Activity.performCreate(Activity.java:8595)
                                                                                                    	at android.app.Activity.performCreate(Activity.java:8573)
                                                                                                    	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1456)
                                                                                                    	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3764)
                                                                                                    	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3922) 
                                                                                                    	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) 
                                                                                                    	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139) 
                                                                                                    	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96) 
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443) 
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:205) 
                                                                                                    	at android.os.Looper.loop(Looper.java:294) 
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8177) 
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) 
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) 
2024-04-23 12:09:18.654 10159-10159 com.example.app         com.example.app                      W  Attempt to remove non-JNI local reference
2024-04-23 12:09:18.690 10159-10159 Process                 com.example.app                      I  Sending signal. PID: 10159 SIG: 9

Expected Behavior

Expected behavior is for the dev server to work and whenever I save files to be able to hotreload changes.

Project Reproduction

https://github.com/kimproductions/capacitor-devserver-not-working

Additional Information

No response

Copy link

ionitron-bot bot commented Apr 23, 2024

This issue has been labeled as type: bug. This label is added to issues that that have been reproduced and are being tracked in our internal issue tracker.

@ionitron-bot ionitron-bot bot removed the triage label Apr 23, 2024
@jcesarmobile
Copy link
Member

As workaround you can remove the / at the end of the url.

@kimproductions
Copy link
Author

As workaround you can remove the / at the end of the url.

Thank fixed it thanks! Doesn't work on localhost but that may be because of my wifi. Works fine when i use the computer's ip address http://192.168.1.136:5173 without / at the end

@jcesarmobile
Copy link
Member

Yeah, you can't use localhost for live reload unless you enable port forwarding.
localhost is "this computer", but if you run on an emulator or a real device, localhost is the emulator or the real device themselves, which don't have the live reload server running, the live reload server is in your computer.

You can enable port forwarding from chrome://inspect/#devices

@carvenl
Copy link

carvenl commented May 2, 2024

As workaround you can remove the / at the end of the url.

I've encountered the same issue. I am using "url": "https://example.com/#/test", and it currently runs in the Android Studio emulator virtual device, but it crashes on a physical device.
There was no such problem in previous versions.

Process: cc.bagua, PID: 15550
java.lang.RuntimeException: Unable to start activity ComponentInfo{cc.bagua/cc.bagua.MainActivity}: java.lang.IllegalArgumentException: allowedOriginRules https:example.com is invalid
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3640)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3797)
	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2215)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:346)
	at android.os.Looper.loop(Looper.java:475)
	at android.app.ActivityThread.main(ActivityThread.java:7889)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1009)
Caused by: java.lang.IllegalArgumentException: allowedOriginRules https:example.com is invalid
	at J.N.MrxnMTWN(Native Method)
	at org.chromium.android_webview.AwContents.b(chromium-TrichromeWebViewGoogle6432.aab-stable-626111933:36)
	at WV.sS.addDocumentStartJavaScript(chromium-TrichromeWebViewGoogle6432.aab-stable-626111933:39)
	at java.lang.reflect.Method.invoke(Native Method)
	at WV.ya.invoke(chromium-TrichromeWebViewGoogle6432.aab-stable-626111933:36)
	at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
	at $Proxy3.addDocumentStartJavaScript(Unknown Source)
	at androidx.webkit.internal.WebViewProviderAdapter.addDocumentStartJavaScript(WebViewProviderAdapter.java:110)
	at androidx.webkit.WebViewCompat.addDocumentStartJavaScript(WebViewCompat.java:823)
	at com.getcapacitor.Bridge.loadWebView(Bridge.java:262)
	at com.getcapacitor.Bridge.<init>(Bridge.java:223)
	at com.getcapacitor.Bridge.<init>(Unknown Source:0)
	at com.getcapacitor.Bridge$Builder.create(Bridge.java:1555)
	at com.getcapacitor.BridgeActivity.load(BridgeActivity.java:48)
	at com.getcapacitor.BridgeActivity.onCreate(BridgeActivity.java:42)
	at android.app.Activity.performCreate(Activity.java:8050)
	at android.app.Activity.performCreate(Activity.java:8030)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1330)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3613)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3797) 
	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) 
	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2215) 
	at android.os.Handler.dispatchMessage(Handler.java:106) 
	at android.os.Looper.loopOnce(Looper.java:346) 
	at android.os.Looper.loop(Looper.java:475) 
	at android.app.ActivityThread.main(ActivityThread.java:7889) 
	at java.lang.reflect.Method.invoke(Native Method) 
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1009) 

@khromov
Copy link

khromov commented May 12, 2024

@jcesarmobile Fantastic, removing the trailing slash from server.url solved it for me as well!

Copy link

ionitron-bot bot commented Jun 11, 2024

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 Jun 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform: android type: bug A confirmed bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants