ionic-cli icon indicating copy to clipboard operation
ionic-cli copied to clipboard

bug: `ionic capacitor run android --livereload` is not rebuilding the app

Open ionitron-bot[bot] opened this issue 6 years ago • 13 comments

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.

ionitron-bot[bot] avatar Aug 19 '19 13:08 ionitron-bot[bot]

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.

brospars avatar Sep 23 '19 15:09 brospars

@WesleyGoncalves @brospars While running ionic capacitor run android -l, what does capacitor.config.json contain?

imhoffd avatar Sep 30 '19 15:09 imhoffd

@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 avatar Oct 01 '19 07:10 brospars

@brospars

  1. Open android/app/src/main/AndroidManifest.xm

  2. Add this to your AndroidManifest.xml in the tag (Tag application already exists) <application android:usesCleartextTraffic="true">

  3. Run live reload with host of your PC ionic capacitor run android -l --address=192.168.2.106 INSTEAD OF 192.168.2.106 YOU PUT YOR PC'S ADDRESS

  4. After run Android Studio with connected device as usual

alexdev888 avatar Oct 02 '19 14:10 alexdev888

@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 avatar Oct 03 '19 08:10 brospars

@brospars, how can we add this to the documentation? In my case, using Android 9, I needed to add this attribute.

alexdev888 avatar Oct 03 '19 08:10 alexdev888

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

brospars avatar Oct 03 '19 09:10 brospars

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

Yes this should be documented ! I was stuck for almost a day on this !

muttalkadavul avatar Nov 27 '19 07:11 muttalkadavul

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

I got it working with the <application android:usesCleartextTraffic="true"> and command ionic capacitor run android --livereload --external

mcelotti avatar Dec 04 '19 22:12 mcelotti

@brospars

  1. Open android/app/src/main/AndroidManifest.xm
  2. Add this to your AndroidManifest.xml in the tag (Tag application already exists) <application android:usesCleartextTraffic="true">
  3. Run live reload with host of your PC ionic capacitor run android -l --address=192.168.2.106 INSTEAD OF 192.168.2.106 YOU PUT YOR PC'S ADDRESS
  4. 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 --external in 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 :)

chilupa avatar Apr 10 '20 04:04 chilupa

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

tx-tim avatar Jul 15 '20 18:07 tx-tim

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.

karunt avatar Jul 05 '21 15:07 karunt

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!!

ajay-gupta25 avatar Apr 26 '23 08:04 ajay-gupta25