ionic-cli
ionic-cli copied to clipboard
bug: `ionic capacitor run android --livereload` is not rebuilding the app
Original issue by @WesleyGoncalves on 2019-08-19T02:04:10Z
The app is not being updated in the Android device after I make changes to it. The live reload is not working.
The app only gets updated if I run ng build, then ionic capacitor copy android or ionic capacitor run android -l, and then run the app in Android Studio.
Any update on this ? I have the same issue (Ubuntu 18.04) ionic-cli compiles when it sees the change but my device is not updated (even if I restart the app)
[ng] 103 unchanged chunks
[ng] chunk {tab2-tab2-module} tab2-tab2-module.js, tab2-tab2-module.js.map (tab2-tab2-module) 4.58 kB [rendered]
[ng] Time: 1082ms
[ng] ℹ 「wdm」: Compiled successfully.
@WesleyGoncalves @brospars While running ionic capacitor run android -l, what does capacitor.config.json contain?
@dwieeb It adds the server url
{
"appId": "io.ionic.blabla",
"appName": "blabla-app",
"bundledWebRuntime": false,
"npmClient": "npm",
"webDir": "www",
"server": {
"url": "http://localhost:8100"
}
}
Edit : I've just noticed that even if I rebuild the app in android studio it doesn't update, I have to run without livereload ionic capacitor run android then rebuild it to see the change (even a simple html change)
@brospars
-
Open
android/app/src/main/AndroidManifest.xm -
Add this to your AndroidManifest.xml in the tag (Tag application already exists)
<application android:usesCleartextTraffic="true"> -
Run live reload with host of your PC
ionic capacitor run android -l --address=192.168.2.106INSTEAD OF 192.168.2.106 YOU PUT YOR PC'S ADDRESS -
After run Android Studio with connected device as usual
@alext0101 Just adding my address worked, thank you !
Using <application android:usesCleartextTraffic="true"> wasn't necessary since I'm targeting API level 27
Maybe, this should be added in the documentation
@brospars, how can we add this to the documentation? In my case, using Android 9, I needed to add this attribute.
We could update these pages :
- https://ionicframework.com/docs/building/android
- https://ionicframework.com/docs/cli/commands/capacitor-run
The first one gives an example of live reload with cordova but not with capacitor and say it doesn't work with localhost:8100 but you need to provide your host IP address.
We could also say that <application android:usesCleartextTraffic="true"> may be needed for API level > 28
We could update these pages :
- https://ionicframework.com/docs/building/android
- https://ionicframework.com/docs/cli/commands/capacitor-run
The first one gives an example of live reload with cordova but not with capacitor and say it doesn't work with
localhost:8100but you need to provide your host IP address.We could also say that
<application android:usesCleartextTraffic="true">may be needed for API level > 28
Yes this should be documented ! I was stuck for almost a day on this !
We could update these pages :
- https://ionicframework.com/docs/building/android
- https://ionicframework.com/docs/cli/commands/capacitor-run
The first one gives an example of live reload with cordova but not with capacitor and say it doesn't work with
localhost:8100but you need to provide your host IP address.We could also say that
<application android:usesCleartextTraffic="true">may be needed for API level > 28
I got it working with the <application android:usesCleartextTraffic="true"> and command ionic capacitor run android --livereload --external
@brospars
- Open
android/app/src/main/AndroidManifest.xm- Add this to your AndroidManifest.xml in the tag (Tag application already exists)
<application android:usesCleartextTraffic="true">- Run live reload with host of your PC
ionic capacitor run android -l --address=192.168.2.106INSTEAD OF 192.168.2.106 YOU PUT YOR PC'S ADDRESS- After run Android Studio with connected device as usual
Don't need to put our PC's address. Just do
- In Android manifest xml, use
android:usesCleartextTraffic="true"in<application> - Run
ionic capacitor run android -l --externalin your ionic app. This should build your app and open your android studio. - Click on Run in Android Studio ( Either an emulator or a real device )
It should get your app running :)
Battled this for several hours before coming across this issue. I finally got livereload to work on android by following the steps above from @brospars with a slight tweak to step 3.
Instead of
`ionic capacitor run android -l --address=192.168.2.106`
I replaced --address with --host and also included the --external option.
So step 3 is
ionic capacitor run android -l --external --host=192.168.2.106 with your PC's address.
When I omit the host(previously address), I get an error saying ERROR_ADDRESS_UNREACHABLE
Is there a reason the livereload option doesn't run with ionic capacitor build android? The benefit with using build vs run is that it opens the Android SDK with the code automatically, but an inconvenience if livereload doesn't work with build. Also, I was able to make the livereload option work by just using the --external option; didn't need to specify the host. For reference, I'm using API level 28.
I was facing the similar issue for one of my react-ionic based capacitor project. This was fixed by adding server: {} in capacitor.config.ts file (or capacitor.config.json).
const config: CapacitorConfig = {
appId: 'io.ionic.starter',
appName: 'appName',
webDir: 'build',
bundledWebRuntime: false,
server: {
url: "http://<REPLACE_YOUR_IP_HERE>:8100", // need to replace your IP here
cleartext: true
},
};
This works for me, hope works for others too!!