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: npx cap build android --prod err_connection_refused localhost #3809

Closed
mwillbanks opened this issue Nov 16, 2020 · 3 comments
Closed

bug: npx cap build android --prod err_connection_refused localhost #3809

mwillbanks opened this issue Nov 16, 2020 · 3 comments

Comments

@mwillbanks
Copy link

mwillbanks commented Nov 16, 2020

Bug Report

Capacitor Version

💊   Capacitor Doctor  💊

Latest Dependencies:

  @capacitor/cli: 2.4.2
  @capacitor/core: 2.4.2
  @capacitor/android: 2.4.2
  @capacitor/electron: 2.4.2
  @capacitor/ios: 2.4.2

Installed Dependencies:

  @capacitor/cli 2.4.2
  @capacitor/android 2.4.2
  @capacitor/core 2.4.2
  @capacitor/ios 2.4.2
  @capacitor/electron not installed

[success] Android looking great! 👌
  Found 12 Capacitor plugins for ios:
    cordova-plugin-advanced-http (3.0.1)
    cordova-plugin-app-version (0.1.9)
    cordova-plugin-browsertab (0.2.0)
    cordova-plugin-buildinfo (4.0.0)
    cordova-plugin-compat (1.2.0)
    cordova-plugin-customurlscheme (5.0.2)
    cordova-plugin-file (6.0.2)
    cordova-plugin-inappbrowser (4.0.0)
    cordova-plugin-intercom (9.2.1)
    cordova-plugin-sign-in-with-apple (0.1.2)
    cordova-universal-links-plugin-fix (1.2.1)
    sentry-cordova (0.17.0)
[success] iOS looking great! 👌

Platform(s)

  • Android

Current Behavior

It appears that it is attempting to access localhost rather than using the generated assets. We've tried multiple ways including:

ionic build --prod
npx cap sync android
npx cap open android

as well as

npx cap build android --prod

both start to load the splash screen and subsequently error about:
Webpage not available
The webpage at http://localhost/ could not be loaded because: net::ERR_CONNECTION_REFUSED

Expected Behavior

It would load the app?

Code Reproduction

There is no specific code reproduction here other than attempting to create an android release.

Other Technical Details

npm --version output: 6.14.7

node --version output: v12.16.2

Additional Context

Looked everywhere, I am out of ideas. When running the development version everything works properly (while the server runs in the background) however, production builds appear to be relaying on having a development server available.

AndroidManifest.xml

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

    <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"
        android:networkSecurityConfig="@xml/network_security_config">

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

            <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" />
        </provider>
    </application>

    <!-- Permissions -->

    <uses-permission android:name="android.permission.INTERNET" />
    <!-- Camera, Photos, input file -->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <!-- Geolocation API -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-feature android:name="android.hardware.location.gps" />
    <!-- Network API -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- Navigator.getUserMedia -->
    <!-- Video -->
    <uses-permission android:name="android.permission.CAMERA" />
    <!-- Audio -->
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
</manifest>

capacitor.config.json

{
  "appId": "io.XXXXXX.XXXXXX",
  "appName": "XXXXXX",
  "bundledWebRuntime": false,
  "npmClient": "npm",
  "webDir": "www",
  "server": {
    "allowNavigation": [
      "*"
    ]
  },
  "plugins": {
    "SplashScreen": {
      "launchAutoHide": false,
      "backgroundColor": "#292f4f",
      "androidSplashResourceName": "screen",
      "androidScaleType": "CENTER_CROP",
      "androidSpinnerStyle": "large",
      "iosSpinnerStyle": "small",
      "spinnerColor": "#e33dc2",
      "showSpinner": true,
      "splashFullScreen": true,
      "splashImmersive": true
    }
  },
  "cordova": {
    "preferences": {
      "AutoHideSplashScreen": "false",
      "BackupWebStorage": "none",
      "FadeSplashScreen": "false",
      "Fullscreen": "false",
      "KeyboardDisplayRequiresUserAction": "false",
      "KeyboardResize": "true",
      "KeyboardResizeMode": "native",
      "ScrollEnabled": "true",
      "SplashMaintainAspectRatio": "true",
      "SplashScreen": "screen",
      "SplashScreenBackgroundColor": "#292F4F",
      "SplashScreenDelay": "4000",
      "SplashShowOnlyFirstTime": "false",
      "android-minSdkVersion": "22",
      "intercom-android-api-key": "android_sdk-xxxxxx",
      "intercom-app-id": "xxxxxx",
      "intercom-ios-api-key": "ios_sdk-xxxxxx",
      "orientation": "portrait",
      "resizeOnFullScreen": "true"
    }
  }
}

@mwillbanks
Copy link
Author

The issue here seems to stem from the following configuration:

  "server": {
    "allowNavigation": [
      "*"
    ]
  },

@jcesarmobile
Copy link
Member

closing as #3834 was merged, will be available on next 2.x release

@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

3 participants