问题
I recently developed a cordova App that is uploaded to google play store. I tested this app on my mobile and simulators for weeks and everything works fine. However, when i download the same app from the playstore it fails to call any of the web services and such doesn't display any content.
cordova : 9.0.1
npm : 6.10.1
cordova-android : 7.0.0
I have gone through every line of code and i can't seem to find the problem, i replaced every single call to window.localStorage
to a global variables just to be able to fix what i thought would be the problem.
<?xml version='1.0' encoding='utf-8'?></code>
<widget defaultlocale="en-US" id="com.test.fr" version="1.0.6" android-versionCode="100050" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:vs="http://schemas.microsoft.com/appx/2014/htmlapps">
<content src="index.html" />
<access origin="*" />
<preference name="SplashScreen" value="screen" />
<preference name="windows-target-version" value="8.1" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<platform name="android">
<icon src="www/res/icon/android/fr_mobile_icon.png" density="ldpi" />
<icon src="www/res/icon/android/fr_mobile_icon.png" density="mdpi" />
<icon src="www/res/icon/android/fr_mobile_icon.png" density="hdpi" />
<icon src="www/res/icon/android/fr_mobile_icon.png" density="xhdpi" />
</platform>
<plugin name="cordova-plugin-device" version="2.0.2" />
<plugin name="cordova-plugin-websql" version="0.0.10" />
<plugin name="cordova-plugin-dialogs" version="2.0.1" />
<plugin name="cordova-plugin-file" version="4.3.3" />
<preference name="target-device" value="handset" />
<preference name="BackupWebStorage" value="local" />
<preference name="android-targetSdkVersion" value="28" />
<preference name="android-minSdkVersion" value="17" />
<preference name="android-maxSdkVersion" value="29" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<plugin name="cordova-custom-config" spec="5.1.0" />
</widget>
Worst part.... No error shown on the device, it just doesn't work.
回答1:
Try adding android:usesCleartextTraffic="true"
to the <application>
in the AndroidManifest.xml
or as below using config.xml
<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:usesCleartextTraffic="true" />
</edit-config>
</platform>
android:usesCleartextTraffic Indicates whether the app intends to use cleartext network traffic, such as cleartext HTTP. The default value for apps that target API level 27 or lower is "true". Apps that target API level 28 or higher default to "false". More info
Cleartext is any transmitted or stored information that is not encrypted or meant to be encrypted. When an app communicates with servers using a cleartext network traffic, such as HTTP, it could raise a risk of eavesdropping and tampering of content which is why in latest Android devices, it's set to
false
by default.
回答2:
First of all, you need to figure out what is the output of this error. To allow debug on a release build use android:debuggable
on application
tag at AndroiManifest.xml
(https://developer.android.com/guide/topics/manifest/application-element).
Then, plug the device to your computer and in dev settings (on your device) enable usb debugging
. Then, navigate to chrome://inspect/#devices
- your device should be appearing and will be a link to your webview.
With the inspector openned, do the request and look to the error on console tab.
I think there's a high chance that the error is a CORS error, may your production server has CORS eabled and then you need to use cordova-plugin-whitelist
correctly to send a origin
to the server, read more about cordova-plugin-whitelist
here: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/
来源:https://stackoverflow.com/questions/57569589/my-app-downloaded-from-the-playstore-fails-to-call-web-service