ionic-team / ionic-cli

The Ionic command-line interface
MIT License
2k stars 653 forks source link

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

Open ionitron-bot[bot] opened 5 years ago

ionitron-bot[bot] commented 5 years ago

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.

brospars commented 5 years ago

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.
imhoffd commented 5 years ago

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

brospars commented 5 years ago

@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)

alexdev888 commented 5 years ago

@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

brospars commented 5 years ago

@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

alexdev888 commented 5 years ago

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

brospars commented 5 years ago

We could update these pages :

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

muttalkadavul commented 4 years ago

We could update these pages :

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 !

mcelotti commented 4 years ago

We could update these pages :

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

chilupa commented 4 years ago

@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

It should get your app running :)

tx-tim commented 4 years ago

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

karunt commented 3 years ago

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.

ajay-gupta25 commented 1 year ago

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