Android published app fails HTTP connect


#1

My app runs fine on a device with the /android-debug.apk but when I wrap it up and submit to the play store, the APK fails to connect through http / https to my server with the http module. I browses the web and found potential issues with the server side SSL certificates. However, before porting my app to ionic2 this whole game worked.
Below is some code to get a better idea.

cordova build --release android 
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore myKey platforms/android/build/outputs/apk/android-release-unsigned.apk MyApp
zipalign -v 4 platforms/android/build/outputs/apk/android-release-unsigned.apk MyApp.apk 

I tried debugging it but there’s no error.

Here’s my config.xml

    <content src="index.html" />
    <access origin="*" />
    <allow-navigation href="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <preference name="webviewbounce" value="false" />
    <preference name="UIWebViewBounce" value="false" />
    <preference name="DisallowOverscroll" value="true" />
    <preference name="android-minSdkVersion" value="16" />
    <preference name="BackupWebStorage" value="none" />
    <preference name="SplashMaintainAspectRatio" value="true" />
    <preference name="FadeSplashScreenDuration" value="300" />
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="3000" />
    <feature name="StatusBar">
        <param name="ios-package" onload="true" value="CDVStatusBar" />
    </feature>
    <plugin name="cordova-sqlite-storage" spec="~2.0.0" />
    <plugin name="phonegap-plugin-push" spec="~1.9.4">
        <variable name="SENDER_ID" value="XYZ" />
    </plugin>
    <plugin name="cordova-plugin-whitelist" spec="~1.3.1" />

And here’s my AndroidManifest.xml

    <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" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
    <uses-permission android:name="${applicationId}.permission.PushHandlerActivity" />
    <permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <permission android:name="${applicationId}.permission.PushHandlerActivity" android:protectionLevel="signature" />

#2

I had to upgrade my android dev version to 25 and update my packaging commands to use

zipalign -v -p 4 platforms/android/build/outputs/apk/android-release-unsigned.apk platforms/android/build/outputs/apk/android-release-unsigned-aligned.apk

apksigner sign --ks ./buyo-release-Playstore.key --out MyApp.apk platforms/android/build/outputs/apk/android-release-unsigned-aligned.apk

#3
cordova plugin add cordova-plugin-whitelist --save

Run the above command in the terminal. It worked for me.