0

I am getting the mentioned error when I tried to build and run apk in android phone. I have deployed my back end server in nestjs and able to call an endpoint http://<server-ip>:3000/batch. I provided the same ip in environment in ionic angular app. When I tried to build, it build fine. I was also able to test the api end point in laptop's browser and all seemed fine. Now when, I exported the apk to android phone and opened the page, I get http failure response for 0 unknown error.

I have no clue as what is wrong and how to debug it.

Followed some threads at -

How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?

and https://better-coding.com/solved-android-cannot-send-data-to-the-server-cleartext-communication-to-not-permitted-by-network-security-policy/

I had a hope that it will probably work but it didn't.

I have cors enabled in my back end server -

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: ['error', 'warn', 'log', 'debug'],
  });
  app.enableCors();
  await app.listen(3000);
}
bootstrap();

And following is the end point -

  @Get()
  @Header('Access-Control-Allow-Origin', '*')
  @Header('Access-Control-Allow-Headers', 'Content-Type, Accept')
  findAll(): Promise<Batch[]> {
    this.logger.log(':: BatchController :: findAll()');
    console.log(':: BatchController :: findAll()');

    return this.batchService.findAll();
  }

When I try to build apk using command ``, there are some errors that I see but it build apk successfully -

chunk {79} 79.527ba05a05dac319dfca.js () 16.5 kB  [rendered]
chunk {80} 80.3f4506b1d5203e22cd1f.js () 14.1 kB  [rendered]
chunk {81} 81.174fab84bae334d8bf15.js () 12.4 kB  [rendered]
chunk {82} 82.d4c013ca3a9ed3f18969.js () 12 kB  [rendered]
chunk {83} 83.e66518b1ed2dd95535c3.js () 11.3 kB  [rendered]
chunk {84} 84.3cb585c911377d7c4d18.js () 11.3 kB  [rendered]
chunk {85} 85.ec4021e8342d212a77db.js () 30.2 kB  [rendered]
chunk {86} 86.f70e4739fdb3010078bf.js () 30.2 kB  [rendered]
chunk {87} 87.c686af6cb65c9c766cfb.js () 6.15 kB  [rendered]
chunk {88} 88.09eb276353a3a1c792b2.js () 3.79 kB  [rendered]
chunk {89} 89.e0df1e6f4267bf57f337.js () 3.79 kB  [rendered]
chunk {90} 90.d3d2fbf3488f7858b2b6.js () 11.2 kB  [rendered]
chunk {91} 91.a30bd68982c40fa7efeb.js () 11.3 kB  [rendered]
chunk {92} 92.3c0f9af8cb7fd7000c50.js () 5.07 kB  [rendered]
chunk {93} 93.794dabceace7a9c56c07.js () 569 bytes  [rendered]
chunk {94} 94.70986cd5f2db8734ff21.js () 7.45 kB  [rendered]
chunk {95} 95.839e6ac1e05c3c5f2884.js () 7.48 kB  [rendered]
chunk {96} 96.792ba97e4675827b03de.js () 9.74 kB  [rendered]
chunk {97} 97.1a4ac4b23d53fd70850c.js () 10.3 kB  [rendered]
chunk {98} 98.cf029c74bf4f7ca23f9d.js () 7.24 kB  [rendered]
chunk {99} 99.494632a928ee566a9b5b.js () 7.08 kB  [rendered]
chunk {100} 100.986962959fcf2a3edbf4.js () 8.71 kB  [rendered]
chunk {101} 101.a8db3368fdd285a43670.js () 8.86 kB  [rendered]
chunk {102} 102.f0497b0c03ca48b04f8f.js () 984 bytes  [rendered]
chunk {103} 103.d662b46b8de8bc82a74a.js () 4.65 kB  [rendered]
chunk {104} 104.4803c534020702e812d6.js () 77.1 kB  [rendered]
chunk {105} 105.e2eebbeebcffb4e201f5.js () 18 kB  [rendered]
chunk {cordova} cordova.22d0b106f4dfd80eb9b7.js (cordova) 21 kB [entry] [rendered]
> cordova.cmd build android --release
config file *-Info.plist requested for changes not found at C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\*-Info.plist, ignoring
config file *-Info.plist requested for changes not found at C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\*-Info.plist, ignoring
config file *-Info.plist requested for changes not found at C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\*-Info.plist, ignoring
config file *-Info.plist requested for changes not found at C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\*-Info.plist, ignoring
config file *-Info.plist requested for changes not found at C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\*-Info.plist, ignoring
config file *-Info.plist requested for changes not found at C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\*-Info.plist, ignoring
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=C:\Users\AAAA\AppData\Local\Android\Sdk (recommended setting)
ANDROID_HOME=C:\Users\AAAA\AppData\Local\Android\Sdk (DEPRECATED)
Subproject Path: CordovaLib
Subproject Path: app
Starting a Gradle Daemon, 1 stopped Daemon could not be reused, use --status for details
> Task :app:preBuild UP-TO-DATE
> Task :CordovaLib:preBuild UP-TO-DATE
> Task :CordovaLib:preReleaseBuild UP-TO-DATE
> Task :CordovaLib:checkReleaseManifest UP-TO-DATE
> Task :CordovaLib:processReleaseManifest UP-TO-DATE
> Task :app:preReleaseBuild UP-TO-DATE
> Task :CordovaLib:compileReleaseAidl NO-SOURCE
> Task :app:compileReleaseAidl NO-SOURCE
> Task :CordovaLib:packageReleaseRenderscript NO-SOURCE
> Task :app:compileReleaseRenderscript UP-TO-DATE
> Task :app:checkReleaseManifest UP-TO-DATE
> Task :app:generateReleaseBuildConfig UP-TO-DATE
> Task :app:prepareLintJar UP-TO-DATE
> Task :app:generateReleaseSources UP-TO-DATE
> Task :CordovaLib:compileReleaseRenderscript UP-TO-DATE
> Task :CordovaLib:generateReleaseBuildConfig UP-TO-DATE
> Task :CordovaLib:generateReleaseResValues UP-TO-DATE
> Task :CordovaLib:generateReleaseResources UP-TO-DATE
> Task :CordovaLib:packageReleaseResources UP-TO-DATE
> Task :CordovaLib:generateReleaseRFile UP-TO-DATE
> Task :CordovaLib:prepareLintJar UP-TO-DATE
> Task :CordovaLib:generateReleaseSources UP-TO-DATE
> Task :CordovaLib:javaPreCompileRelease UP-TO-DATE
> Task :CordovaLib:compileReleaseJavaWithJavac UP-TO-DATE> Task :CordovaLib:processReleaseJavaRes NO-SOURCE
> Task :CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForRelease UP-TO-DATE
> Task :app:javaPreCompileRelease UP-TO-DATE
> Task :app:mainApkListPersistenceRelease UP-TO-DATE
> Task :app:generateReleaseResValues UP-TO-DATE
> Task :app:generateReleaseResources UP-TO-DATE
> Task :app:mergeReleaseResources UP-TO-DATE
> Task :app:createReleaseCompatibleScreenManifests UP-TO-DATE
> Task :app:processReleaseManifest UP-TO-DATE
> Task :app:processReleaseResources UP-TO-DATE
> Task :app:compileReleaseJavaWithJavac UP-TO-DATE
> Task :app:compileReleaseNdk NO-SOURCE
> Task :app:compileReleaseSources UP-TO-DATE

C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\app\src\main\res\drawable-land-hdpi\screen.png: Error: The drawable "screen" in drawable-land-hdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
> Task :app:lintVitalRelease
C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\app\src\main\res\drawable-land-ldpi\screen.png: Error: The drawable "screen" in drawable-land-ldpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\app\src\main\res\drawable-land-mdpi\screen.png: Error: The drawable "screen" in drawable-land-mdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\app\src\main\res\drawable-land-xhdpi\screen.png: Error: The drawable "screen" in drawable-land-xhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\app\src\main\res\drawable-land-xxhdpi\screen.png: Error: The drawable "screen" in drawable-land-xxhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\app\src\main\res\drawable-land-xxxhdpi\screen.png: Error: The drawable "screen" in drawable-land-xxxhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\app\src\main\res\drawable-port-hdpi\screen.png: Error: The drawable "screen" in drawable-port-hdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\app\src\main\res\drawable-port-ldpi\screen.png: Error: The drawable "screen" in drawable-port-ldpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\app\src\main\res\drawable-port-mdpi\screen.png: Error: The drawable "screen" in drawable-port-mdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\app\src\main\res\drawable-port-xhdpi\screen.png: Error: The drawable "screen" in drawable-port-xhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\app\src\main\res\drawable-port-xxhdpi\screen.png: Error: The drawable "screen" in drawable-port-xxhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\app\src\main\res\drawable-port-xxxhdpi\screen.png: Error: The drawable "screen" in drawable-port-xxxhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]

   Explanation for issues of type "MissingDefaultResource":
   If a resource is only defined in folders with qualifiers like -land or -en,
   and there is no default declaration in the base folder (layout or values
   etc), then the app will crash if that resource is accessed on a device
   where the device is in a configuration missing the given qualifier.

   As a special case, drawables do not have to be specified in the base
   folder; if there is a match in a density folder (such as drawable-mdpi)
   that image will be used and scaled. Note however that if you  only specify
   a drawable in a folder like drawable-en-hdpi, the app will crash in
   non-English locales.

   There may be scenarios where you have a resource, such as a -fr drawable,
   which is only referenced from some other resource with the same qualifiers
   (such as a -fr style), which itself has safe fallbacks. However, this still
   makes it possible for somebody to accidentally reference the drawable and
   crash, so it is safer to create a default dummy fallback in the base
   folder. Alternatively, you can suppress the issue by adding
   tools:ignore="MissingDefaultResource" on the element.

   (This scenario frequently happens with string translations, where you might
   delete code and the corresponding resources, but forget to delete a
   translation. There is a dedicated issue id for that scenario, with the id
   ExtraTranslation.)

C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\app\src\main\res\xml\network_security_config.xml:4: Error: Missing includeSubdomains attribute [NetworkSecurityConfig]
        <domain>localhost</domain>
         ~~~~~~

   Explanation for issues of type "NetworkSecurityConfig":
   Ensures that a <network-security-config> file, which is pointed to by an
   android:networkSecurityConfig attribute in the manifest file, is valid

   https://developer.android.com/preview/features/security-config.html

13 errors, 0 warnings

> Task :app:mergeReleaseShaders UP-TO-DATE
> Task :app:compileReleaseShaders UP-TO-DATE
> Task :app:generateReleaseAssets UP-TO-DATE
> Task :CordovaLib:mergeReleaseShaders UP-TO-DATE
> Task :CordovaLib:compileReleaseShaders UP-TO-DATE
> Task :CordovaLib:generateReleaseAssets UP-TO-DATE
> Task :CordovaLib:packageReleaseAssets UP-TO-DATE
> Task :app:mergeReleaseAssets UP-TO-DATE
> Task :app:signingConfigWriterRelease UP-TO-DATE
> Task :app:transformClassesWithDexBuilderForRelease UP-TO-DATE
> Task :app:transformDexArchiveWithExternalLibsDexMergerForRelease UP-TO-DATE
> Task :app:transformDexArchiveWithDexMergerForRelease UP-TO-DATE
> Task :app:mergeReleaseJniLibFolders UP-TO-DATE
> Task :CordovaLib:compileReleaseNdk NO-SOURCE
> Task :CordovaLib:mergeReleaseJniLibFolders UP-TO-DATE
> Task :CordovaLib:transformNativeLibsWithMergeJniLibsForRelease UP-TO-DATE
> Task :CordovaLib:transformNativeLibsWithIntermediateJniLibsForRelease UP-TO-DATE
> Task :app:transformNativeLibsWithMergeJniLibsForRelease UP-TO-DATE
> Task :app:processReleaseJavaRes NO-SOURCE
> Task :app:transformResourcesWithMergeJavaResForRelease UP-TO-DATE
> Task :app:packageRelease
> Task :app:assembleRelease
> Task :app:cdvBuildRelease

BUILD SUCCESSFUL in 3m 56s
42 actionable tasks: 2 executed, 40 up-to-date
Built the following apk(s):
        C:\Users\AAAA\Drive\documents\workspace-vs-code\sample-app-ionic-master\platforms\android\app\build\outputs\apk\release\app-release-unsigned.apk
> native-run.cmd android --app platforms\android\app\build\outputs\apk\release\app-release-unsigned.apk
[native-run] No hardware devices found, attempting emulator...
[native-run] ERR_NO_TARGET: No targets devices/emulators available. Cannot create AVD because there is no suitable API installation. Use --sdk-info to reveal missing packages and other issues.
[native-run]
[native-run]    More details for this error may be available online:
[native-run]
[native-run]    https://github.com/ionic-team/native-run/wiki/Android-Errors
[ERROR] An error occurred while running subprocess native-run.

        native-run.cmd android --app platforms\android\app\build\outputs\apk\release\app... exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.

AndroidManifest file -

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="2" android:versionName="0.0.2" package="us.zoom.ionicdemo" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:networkSecurityConfig="@xml/network_security_config" android:supportsRtl="true" android:usesCleartextTraffic="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.BROADCAST_STICKY" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
</manifest>

network-security-config.xml -

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain>localhost</domain>
    </domain-config>
</network-security-config>

I tried to update network-security-config.xml to below but it resets to above when I run build command -

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">your domain or ip address</domain>
    </domain-config>
</network-security-config>

Struggling with it since last two days. If any other info is needed, please let me know.

a p
  • 1,121
  • 6
  • 26
  • 51

1 Answers1

2

In order to solve this error, its related to splashscreen in config.xml. There are declarations for splash density and inside it there are port-type.. and land-type.., keep everything as it is except for land declarations, every place that contains land-type.. keyword change it to just type..., for example, land-hdpi change to hdpi and for port-hdpi keep it the same without change.

    <splash density="ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png" />
    <splash density="mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png" />
    <splash density="hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png" />
    <splash density="xhdpi" src="resources/android/splash/drawable-land-xhdpi-screen.png" />
    <splash density="xxhdpi" src="resources/android/splash/drawable-land-xxhdpi-screen.png" />
    <splash density="xxxhdpi" src="resources/android/splash/drawable-land-xxxhdpi-screen.png" />
    <splash density="port-ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png" />
    <splash density="port-mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png" />
    <splash density="port-hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png" />
    <splash density="port-xhdpi" src="resources/android/splash/drawable-port-xhdpi-screen.png" />
    <splash density="port-xxhdpi" src="resources/android/splash/drawable-port-xxhdpi-screen.png" />
    <splash density="port-xxxhdpi" src="resources/android/splash/drawable-port-xxxhdpi-screen.png" />
    <splash density="land-ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png" />
    <splash density="land-mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png" />
    <splash density="land-hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png" />
    <splash density="land-xhdpi" src="resources/android/splash/drawable-land-xhdpi-screen.png" />
    <splash density="land-xxhdpi" src="resources/android/splash/drawable-land-xxhdpi-screen.png" />
    <splash density="land-xxxhdpi" src="resources/android/splash/drawable-land-xxxhdpi-screen.png" />

And for http errors, if you are running your apidomain as http and you device is sdk version 28+ then you need to change it to https..

Mostafa Harb
  • 1,558
  • 1
  • 6
  • 12
  • Thanks very much Mostafa. After much banging yesterday, I got to know that I will need https. I am gonna try the splash screen solution you suggested. Upvoted. Choosing as an answer too. Could you please also help as why I see that `NetworkSecurityConfig` error? – a p May 21 '20 at 09:18
  • Change it from resources/android/xml/networksec...config.xml as here https://stackoverflow.com/questions/58608249/ionic-network-security-config – Mostafa Harb May 21 '20 at 16:53
  • removing `land` gives following error - `Source path does not exist: resources/android/splash/drawable-land-hdpi-screen.png [ERROR] An error occurred while running subprocess cordova.` and now its not building even – a p May 21 '20 at 17:05
  • Also, changing network-security-config.xml as stated in the link has no effect. For whatever reasons, it reverts the change by itself while building. – a p May 21 '20 at 17:21
  • For the land change, you also need to change its path, give me like an hour and i'll reach my computer and edit the answer to the exact solution so you just copy and paste it, and for the network problem, i didn't face the problem before but though i'll find a solution for you for sure but just give me an hour or hour and 20 min as maximum. – Mostafa Harb May 21 '20 at 17:39
  • @apun i've edited the answer for drwabales and after you do it tell me if it succeeds or not.. – Mostafa Harb May 21 '20 at 19:13
  • thank you mate. now tha splash screen error is gone. But `` still remains. Even if I update it to `https://...`, it resets it to `localhost`. Seems its being fetched from another place, any idea? – a p May 26 '20 at 15:45
  • I think its being fetched from config.xml, as i remmeber its before prefences, there they always fix a line in it to let the cors error be removed, see at and reply if not found.. – Mostafa Harb May 26 '20 at 16:15
  • I was updating it at a wrong place it seems, updating it at `resources/android/xml/network-security-config` which is referred in `config.xml` helped to get away with the error. Thanks a bunch, mate. – a p May 27 '20 at 09:30