Debugging Ionic 4 App in Appium WebdriverIO not working : WebView missing - ionic-framework

I am trying to debug an Ionic 4 app using Appium & WebdriverIO. I am receiving feedback that I need to enable Webview in my app in order for this to work. The problem is I cannot find a single reference as to how to do this in Ionic anywhere.
I have also attempted to run my app in Browserstack where for the same reason, it won't run at all.
Can someone from Ionic comment on the correct approach to this, that will work for Android and iOS platforms, based on the same Ionic code.

The solution comes in a few steps.
1 - Enable Webview
In the config.xml file, make sure you set the following:
<preference name="WKWebViewOnly" value="true" />
This has the effect of setting :
<application
android:debuggable="true"
2 - Debug Build
In addition to point 1, note that for a production release build, we use the command :
$ ionic cordova build android --prod --release
However, Android does something clever behind the scenes in that this build can only be debugged locally for security reasons. So, no matter what you do, when you try and run this up in Browserstack, it will not provide webview as a context. We fix this by using the debug build flag:
$ ionic cordova build android --prod --debug
3 - Bonus Bug
Unfortunately, there is a bug in the Android Debug build process. So there is one more step to cover. You have to run zipalign twice when you're working on the debug build. Don't ask me why! You just do...
Debug > "%ANDROID_HOME%\build-tools\28.0.3\zipalign" -f 4 app-debug.apk temp.apk // zip-align
Debug > "%ANDROID_HOME%\build-tools\28.0.3\zipalign" -f 4 temp.apk SensorNode.apk // need to do it twice because of android bug!!!
Debug > "%ANDROID_HOME%\build-tools\28.0.3\apksigner" sign --ks my-release-key.jks --v1-signing-enabled true --v2-signing-enabled true SensorNode.apk

Related

Issue when I use ionic cordova run android

I am getting an issue when I try to run with command line
ionic cordova run android
The error that it diplays is this one:
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.
But the thing is that I created a device in the Android Studio:
so I wonder what could the problem be? Thanks
You need to launch the emulator and keep it running before executing the command ionic cordova run android
Click on the Play icon in the Virtual Devices list to launch the emulator.
Might not be the answer you're looking for but generally, I use:ionic cordova build android
Then open the platform/android directory in Android Studio.
Maybe you should try this :
for see avaliables devices this:
ionic cordova run android --list
for run android app on device this:
ionic cordova run android --device --verbose
i hope help you.
Make sure you have the following variables set in your environment.
export ANDROID_HOME=$HOME/Library/Android/sdk
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export ANDROID_AVD_HOME=$HOME/.android/avd

How to update my apk every time I make changes on my template or code changes?

How to update my apk every time I make changes on my template or code changes.
You can use the livereload feature of ionic cordova emulate or ionic cordova run to run the code on an emulator or device and see the changes live as as you code.
Here's how with the emulator:
ionic cordova emulate android --list to get a list of available emulator targets to copy into the next command.
ionic cordova emulate --livereload android -- --target="[TARGET]"
See the CLI docs for more info.
You can do livereload from a ionic cordova run <platform>, if it's an apk i assume that is for android so you can do this:
ionic cordova run android --livereload
For more options like specific port you can take a look on the docs

how to resolve installation problem in device ionic 4

I'm trying install .APK in my divece but I get the following error "app was not installed", I'm using ionic v 4 and my divece is android 6.0.1, any idea ?
Use this command for V4 :
ionic cordova build --release android
This will generate unsigned apk file under
platforms/android/build/outputs/apk/your-project-name.apk
And simply download apk file to your phone and install it. More details can be found here
I faced this error before and the cause was that using unsigned APK or the device contains app with same "App Id"
So to Solve it, Please Follow this instructions:
Use this Command
ionic cordova build android --prod
Then Try to remove any other apps from your phone that may have same app id (any old versions or sample apps) or change your app id from config.xml (before build of course)
<widget id="com.android.YOUR_UNIQE_APP_ID" ... >

How can I install my ionic app on my android phone?

I'm trying to install my ionic app on my android phone. I tried
install my ionic app on my android phone
The app ran on my phone, but when I ran the same command to run a different app, the app was replaced on my mobile. How can I keep both? I don't intend to modify any of these apps, they are ready. I tried these commands as well:
ionic cordova build android --prod --release
and
ionic cordova run android --prod --release
I got this error message:
[ERROR] An error occurred while running cordova run android --release
(exit code 1)
By default, it will overwrite the previous version. You can keep the both app using below way:
Check the config.xml file, and change the id of the app.
<widget id="new.app.id" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
Now, it will be considered as a different app and will not replace the previous one.

Ionic 2 application take too much to launch on android device each and everytime.?

I already try this command : ionic build android --prod --release but still same result. How can one reduce the launching time of an ionic 2 application?
Check the plugins, there must be a problem with some plugin that would give error and increase loading time.
Add lazy loading in some components or upgrade ionic version3+ which brings angular 4