Cordova : how to debug android --prod build - android

I have an issue with a cordova application which occurs only when building it with the command : cordova build android --prod --release
When building in debug mode, everything works fine.
I use chrome://inspect to debug my app, but this work only with debug build
How can I inspect and debug my app when building for production ?
Edit: no solution, this seem to be impossible to do.

If someone wants to do debug in production, is possible using this configuration in the config.xml file, for android:
<widget ... >
<name>myapp</name>
<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application ... android:debuggable="true" />
</edit-config>
</platform>

You can't debug the release version of your application with chrome://inspect because debugging in release version is deactivated. You have to use the debug version to debug your app.

Related

How or Where Cordova platform add android get the minSdkVersion value?

Good day,
I have a cordova mobile project, and I using "cordova platform add android" command to add my android platform.
In my config.xml, I set the minSdkVersion to 26 as follow:
<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:allowBackup="false" />
<application android:networkSecurityConfig="#xml/network_security_config" />
<uses-sdk android:minSdkVersion="26" />
</edit-config>
When I run "cordova platform add android" command, the "/platforms/android" folder and its files will be removed and auto generated. after it auto generate, I check the cdv-gradle-config.json file under "platforms/android", and found the "MIN_SDK_VERSION": 22.
May I know where is this "22" come from? or any mistaken I did to cause this issue?
My cordova version is 10.0.0 (cordova-lib#10.1.0).
My gradle version is 4.7.
Set this code in config.xml
<preference name="android-minSdkVersion" value="22" />
<preference name="android-targetSdkVersion" value="31" />
This is the only tip that works.

Cordova Android release builds Ajax not working

Ajax calls are not working only in release builds but are fine in debug builds. I'm doing all calls over https. There are no CORS errors. Note that the issue only appears on Android, not on iOS.
I use Let's Encrypt SSL certs on the back end.
SHA256withRSA
I have tried every fix available on SO:
<plugin name="cordova-plugin-enable-cleartext-traffic" space="^2.1.0" />
I verified that I have android:usesCleartextTraffic="true" in manifest in the application node
I have added to config.xml
<access origin="*" />
<allow-navigation href="*" />
<preference name="AndroidInsecureFileModeEnabled" value="true" />
and also
<edit-config xmlns:android="http://schemas.android.com/apk/res/android" file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:networkSecurityConfig="#xml/network_security_config" />
</edit-config>
And in res/xml created a file network_security_config.xml with content
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">mydomain.com</domain>
</domain-config>
</network-security-config>
I have verified that my Let's Encrypt SSL certificate is valid, it is. I do not have whitelist plugin anymore due to Android 10+
Version are
Cordova Android 10.1.1
Cordova 10.0.0
Tested on real device running Android 6.0.1 (have to support older phones)
Nothing seems to work. What can I try next?
You should check if you get any CORS erros. If you run your app on file: you might need AndroidInsecureFileModeEnabled in config.xml
I suggest you to use the WebViewAssetLoader with cordova-android#10. Please check out the announcement https://cordova.apache.org/announcements/2021/07/20/cordova-android-10.0.0.html
I will answer my own question, it might save someone A LOT of time.
The issue is that I'm using let's encrypt SSL certificates on Windows Server via Win-Acme and I had been testing on Android 6.1.0.
Following this post I just noticed that Let's Encrypt SSL certificates will not work anymore on Android < 7.1.1
Tested on Android 11 and it just worked.

net::ERR_CLEARTEXT_NOT_PERMITTED error on Ionic Android live reload [duplicate]

This question already has answers here:
Why am I seeing net::ERR_CLEARTEXT_NOT_PERMITTED errors after upgrading to Cordova Android 8?
(19 answers)
Closed 3 years ago.
When I run ionic cordova run android --livereload I get this error:
net::ERR_CLEARTEXT_NOT_PERMITTED (http://192.168.0.5:8100/)
I'm targeting Android SDK 28. I understand that Android does not allow plain HTTP connections anymore.
Is there a workaround?
Add this attribute to <widget> tag in your config.xml:
<widget ... xmlns:android="http://schemas.android.com/apk/res/android">
Add this code to your config.xml:
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:usesCleartextTraffic="true" />
</edit-config>
Don't forget to revert these changes when you build release APK file.

Develop PhoneGap app for old android device

I have a simple, but useful app for an old android device I want to develop with Cordova PhoneGap. Going through their tutorial, by default, the current version of cordova requires android level 14 api to build apps, but I've done the following to get the app to build on my old 2.3.6 device...
In /config.xml add the following in the platform->android tag
<platform name="android">
<allow-intent href="market:*" />
<preference name="android-minSdkVersion" value="10" />
<preference name="android-targetSdkVersion" value="10" />
</platform
Edit these lines in the /platforms/android/AndroidManifest.xml file
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="fi.blogspot.codinginthecold" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10" tools:overrideLibrary="org.apache.cordova" />
Like I said, the HelloWorld app compiles on the device without error, but when I actually run the app, it says the app has unfortunately stopped.
My question: As the above method failed to run the simplest app, what is best way to develop PhoneGap apps for old android devices?
Thanks.

Debug Ionic application with android:debuggable="false"

A have installed my Ionic application on real device. The app is released, signed and has android:debuggable="false".
I faced some problems on that specific device and I need to debug it (not to create and install new --debug build).
Is there some way to debug it? To "attach" it somehow to a keystore to be authorised, or something else...? Any ideas?
I am still trying to find a better way, but so far I am able to debug my Ionic app (a signed --release build) running on a real device via the Chrome (desktop) console, by specifying:
<application android:debuggable="true">
directly in the AndroidManifest.xml file. The attribute in not overwritten when I build the project with the Ionic CLI.
What I would prefer is to set the attribute from the config.xml file, so I don't have to add it again manually in AndroidManifest.xml when I remove/add the platform.
You can add this in your config.xml to solve it.
<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:debuggable="true" />
</edit-config>
Then, you can debug in Chrome.
I've just faced a similar issue (I wanted to create a debuggable Cordova app with cordova build android --release) and I've also wanted to add something to the Cordova config.xml instead of directly editing AndroidManifest.xml, which is generally a bad idea.
The following piece of code worked for me on Cordova 8.1.2, Cordova Android platform version 7.1.4. Just put this inside your config.xml file (somewhere inside the widget tag) and you should be good to go:
<config-file mode="merge" parent="/manifest" platform="android" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:debuggable="true" />
</config-file>
This will also cause the :app:lintVitalRelease linter to give you a [HardcodedDebugMode] error (and for good reason), but the APK will build fine regardless.

Categories

Resources