apache / cordova

Apache Cordova
https://cordova.apache.org/
584 stars 61 forks source link

Error upgrade api lvl 31 in webview cordova 11 #353

Closed seadramdesenv closed 1 year ago

seadramdesenv commented 1 year ago

Recently our team had to upgrade the target sdk of our Android Cordova generated app to 31 and cordova itself to 11, from, respectively 30 and 10, due to Playstore changing it's policies and forcing apks generated to be of sdk 31 or higher, but we ran into a problem specifically with our login button in the first page where it apparently doesnt throw any errors and just doesnt work. Very little changes were made to the code from the version prior to it and it works fine in the web environment but not in the App using WebView, the most we get is the following message :

ADB LOG

    --------- beginning of system
2022-11-21 14:01:36.821 4359-4359/? D/PowerManagerService: [api] userActivity : event: 0 flags: 0 (uid: 1000 pid: 4359) eventTime = 1764524030
2022-11-21 14:01:36.822 4359-4359/? D/InputDispatcher: Inject motion (0): action=0x0, time=1764524030603000, f=0x0, d=0
2022-11-21 14:01:36.822 4359-4507/? I/InputDispatcher: Delivering touch to (4716): action: 0x4, f=0x0, d=0, 'cc87bd3', t=1 
2022-11-21 14:01:36.822 4359-4507/? I/InputDispatcher: Delivering touch to (29761): action: 0x0, f=0x0, d=0, '63726c7', t=1 
2022-11-21 14:01:36.823 4359-4507/? D/PowerManagerService: [api] userActivityFromNative : 430 (event: 2 flags: 0) eventTime = 1764524030
2022-11-21 14:01:36.823 29761-29761/br.com.flexmobile.distrioeste.pedidoweb I/ViewRootImpl@d02df03[MainActivity]: ViewPostIme pointer 0
2022-11-21 14:01:36.823 4359-4507/? D/PowerManagerService: UserActivityStateListenerState: 1
2022-11-21 14:01:36.829 4359-4359/? D/PowerManagerService: [api] userActivity : event: 0 flags: 0 (uid: 1000 pid: 4359) eventTime = 1764524039
2022-11-21 14:01:36.838 4359-4359/? D/PowerManagerService: [api] userActivity : event: 0 flags: 0 (uid: 1000 pid: 4359) eventTime = 1764524048
2022-11-21 14:01:36.846 4359-4359/? D/PowerManagerService: [api] userActivity : event: 0 flags: 0 (uid: 1000 pid: 4359) eventTime = 1764524055
2022-11-21 14:01:36.855 4359-4359/? D/PowerManagerService: [api] userActivity : event: 0 flags: 0 (uid: 1000 pid: 4359) eventTime = 1764524064
2022-11-21 14:01:36.863 4359-4359/? D/PowerManagerService: [api] userActivity : event: 0 flags: 0 (uid: 1000 pid: 4359) eventTime = 1764524072
2022-11-21 14:01:36.871 4359-4359/? D/PowerManagerService: [api] userActivity : event: 0 flags: 0 (uid: 1000 pid: 4359) eventTime = 1764524081
2022-11-21 14:01:36.879 4359-4359/? D/PowerManagerService: [api] userActivity : event: 0 flags: 0 (uid: 1000 pid: 4359) eventTime = 1764524089
2022-11-21 14:01:36.888 4359-4359/? D/PowerManagerService: [api] userActivity : event: 0 flags: 0 (uid: 1000 pid: 4359) eventTime = 1764524098
2022-11-21 14:01:36.897 4359-4359/? D/PowerManagerService: [api] userActivity : event: 0 flags: 0 (uid: 1000 pid: 4359) eventTime = 1764524106
2022-11-21 14:01:36.913 4359-4508/? D/InputReader: Btn_touch(7): value=0 when=1764524.123492
2022-11-21 14:01:36.913 4359-4508/? I/InputReader: Touch event's action is 0x1 (id=2, t=0) [pCnt=1, s=] when=1764524.123492
2022-11-21 14:01:36.914 4359-4359/? D/PowerManagerService: [api] userActivity : event: 0 flags: 0 (uid: 1000 pid: 4359) eventTime = 1764524123
2022-11-21 14:01:36.914 4359-4359/? D/InputDispatcher: Inject motion (0): action=0x1, time=1764524123492000, f=0x0, d=0
2022-11-21 14:01:36.915 4359-4507/? I/InputDispatcher: Delivering touch to (29761): action: 0x1, f=0x0, d=0, '63726c7', t=1 
2022-11-21 14:01:36.915 29761-29761/br.com.flexmobile.distrioeste.pedidoweb I/ViewRootImpl@d02df03[MainActivity]: ViewPostIme pointer 1
2022-11-21 14:01:36.950 29761-29761/br.com.flexmobile.distrioeste.pedidoweb D/InputMethodManager: HSIFW - flag : 0
2022-11-21 14:01:36.951 4359-4755/? V/InputMethodManagerService: Client requesting input be hidden
2022-11-21 14:01:36.951 4359-4755/? V/InputMethodManagerService: hideCurrentInputLocked : shouldHideSoftInput is false
2022-11-21 14:01:36.959 3899-3949/? E/Netd: getNetworkForDns: getNetId from enterpriseCtrl is netid 0
2022-11-21 14:01:36.962 4359-4602/? I/ChimeraAggressivePolicyHandler: executePolicy() - triggerSource: TRIGGER_SOURCE_LMKD
2022-11-21 14:01:36.963 4359-4602/? I/ChimeraAggressivePolicyHandler: available memory: 959708, free memory target: 645120, quit chimera
2022-11-21 14:01:36.972 4359-4755/? D/NetdEventListenerService: DNS Requested by : 1297, 10874
2022-11-21 14:01:36.973 3899-3955/? E/Netd: getNetworkForDns: getNetId from enterpriseCtrl is netid 0
2022-11-21 14:01:37.974 31592-31592/? W/adbd: timeout expired while flushing socket, closing
2022-11-21 14:01:38.071 3833-3833/? I/io_stats: !@ 179,0 r 189261484 4776762830 w 50776343 627152132 d 5203751 221981164 f 3159409 11441507 iot 85065684 67511781 th 51200 51200 49144 pt 39016 inp 0 0 1764525.280
2022-11-21 14:01:38.138 4716-4867/? D/NetworkController.SecMobileSignalController(0/1): onSignalStrengthsChanged level=2
2022-11-21 14:01:38.139 4716-4867/? D/MobileSignalIconsSelector: getDataIconGroup(): 13
2022-11-21 14:01:38.141 4716-4867/? D/MobileSignalIconsSelector: getDataIconGroup(): connected=true,enabled=true,level=1,inetCondition=1,dataIconGroup=DataIconGroup(4G),activityIn=false,activityOut=false,lastModified=11-21 14:01:38.139,dataSim=true,networkName=TIM 48|TIM,networkNameData=TIM 48|TIM,dataConnected=false,roaming=false,isDefault=false,isEmergency=false,airplaneMode=false,carrierNetworkChangeMode=false,userSetup=true,defaultDataOff=false,cdmaEriIconIndex=-1,cdmaEriIconMode=-1,callState=0,voWifiConnected=false,shouldShowDisabledDataIcon=false,bluetoothTethered=false,isLTEFemtoCell=false,cardOperator=OTHERS,optionalRadioTech=0,isCAIndicator=false,isLimitedStateForCTCSlaveVoLTE=false,isSWRoaming=false,isMobileDataSettingEnabled=false,nwBoosterRilEnabled=false,nwBoosterSettingEnabled=false,emergencyModeActivated=false,ismmW5G=false,slotId=0,simState=LOADED,isDefaultDataSlot=true, iconSet = [I@2c05b00

Some of the attempts

Tried using Webview with a basic Flutter app and it worked fine, also tested it in the regular web environment built with Java and Angular and also worked without issues.

My AndroidManifest

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10903" android:versionName="1.9.3" package="br.com.flexmobile.flexmobile.pedidoweb" 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:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:exported="true" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@style/Theme.AppCompat.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>
</manifest>

My Config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="br.com.flexmobile.flexmobile.pedidoweb" version="1.9.3" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Vendas Flexmobile</name>
    <description />
    <author email="flexmobile@flexmobile.com.br" href="http://flexmobile.com.br"> Flexmobile
    </author>
    <icon src="res/icon/icon.png" />
    <content src="index.html" />
    <access origin="*" />
    <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">
        <preference name="android-targetSdkVersion" value="31" />
        <preference name="AndroidInsecureFileModeEnabled" value="true" />
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <plugin name="cordova-plugin-x-toast" spec="^2.6.0" />
    <preference name="loadUrlTimeoutValue" value="700000" />
    <preference name="AppendUserAgent" value="appinwebview" />
</widget>
breautek commented 1 year ago

Your ADB output doesn't really show anything relevant (it shows beginning of system boot but sometime before the application initializes Cordova).

However, problems inside the webview generally indicates a logical problem in the application itself. That is Cordova is a packaging tool that loads up web assets into a webview, but from there Cordova is fairly hands off.

I would try using Chrome's web inspector, which may give us further insights on your issue via the JavaScript console. Cordova debug builds have web inspector access enabled, so by using either the simulator or a physical device via USB, you can remotely debug the webview via the Chrome web developer tools.

seadramdesenv commented 1 year ago

I wasn't able to debug correctly, but the way it went, it's debugging now and I found the method that causes the error

Before updating android cordova to 11 I used targetsdk as 30 and changing it to 31 stops my authentication working

image

I imagine that something changed in question when using sdk 31 but debugging I still couldn't identify it, but since it no longer involves cordova I appreciate the help

Thank you even more if you have any suggestions for analysis

If you want I can send you the source. thanks

breautek commented 1 year ago

HTTP Status 400 Bad Request is a server error. Assuming you're following specs/guidelines, it generally something used on the server to indicate that the client sent something to the server that wasn't expected, or it didn't follow the API.

If your server returns error data, it would be in the response. Otherwise you'll need to look at your server logs to gain further insight, assuming that your server application logs out error details to learn why it might be returning a 400 instead of the expected response.

Nothing here indicates an issue with Cordova itself, so I'll be closing this issue. Should you isolate your issue further and find an actual bug within Cordova, please open a new issue with the newfound information.