Replies: 6 comments 6 replies
-
I'm having the same issue but with a different plugin: @ionic-native/app-version, I get an error with the message: |
Beta Was this translation helpful? Give feedback.
-
@Flaviu989 I've found this to work for me: Assume I have generated an Ionic/Angular app with I explicitly install my capacitor plugins in my ├── apps
│ ├── capacitor-app
│ │ ├── package.json # this one must have your capacitor plugins installed as a dependency
├── package.json # here you can install your non-capacitor dependencies for your `capacitor-app` and ionic/capacitor dev dependencies So this is my {
"name": "capacitor-app",
"devDependencies": {
"@capacitor/cli": "^4.4.0"
},
"dependencies": {
"@capacitor/filesystem": "^4.1.3"
}
} My The reason you have to explicitly install your capacitor plugins in your app (in my example - I can run the usual capacitor commands to generate ios/android capacitor projects, sync, run etc. for # nx run <projec-name>:<capacitor-command>
nx run capacitor-app:<capacitor-command> Examples of different capacitor commands in nx for the nx run capacitor-app:add
nx run capacitor-app:add:ios
nx run capacitor-app:add:android nx run capacitor-app:sync
nx run capacitor-app:sync:ios
nx run capacitor-app:sync:android nx run capacitor-app:open
nx run capacitor-app:open:ios
nx run capacitor-app:open:android nx run capacitor-app:run
nx run capacitor-app:run:ios
nx run capacitor-app:run:android |
Beta Was this translation helpful? Give feedback.
-
to ask a potentially silly question: do you guys have the Capacitor plugins listed in the application project's own either way, without listing them in the application project directly, the plugin files won't be copied into your application build.. |
Beta Was this translation helpful? Give feedback.
-
alrighty, so.. "little" teaser here: I've got a workspace, configured with getting Capacitor to play nicely inside a Nx workspace is incredibly fiddly.. I don't have anything to share with you guys right now, but I will fork and de-brand my current work workspace project over the weekend. in the meantime, here are a few critical points that helped me get this running:
to get Capacitor plugin files to first ensure the app entry in your multi-app then ensure that all your Capacitor plugins are listed in your application project's
for example: {
"name": "awesome-app",
"dependencies": {
"@capacitor/android": "4.0.1",
"@capacitor/core": "4.0.1",
"@capacitor/network": "4.0.1",
"@capacitor/ios": "4.0.1",
"@capacitor/app": "4.1.0",
"@capacitor/haptics": "4.0.1",
"@capacitor/keyboard": "4.0.1",
"@capacitor/splash-screen": "4.0.1",
"@capacitor/status-bar": "4.0.1"
},
"devDependencies": {
"@capacitor/cli": "4.0.1",
"@ionic/cli": "6.20.3"
},
"resolutions": {
"@capacitor/android": "file:../../node_modules/@capacitor/android",
"@capacitor/core": "file:../../node_modules/@capacitor/core",
"@capacitor/network": "file:../../node_modules/@capacitor/network",
"@capacitor/ios": "file:../../node_modules/@capacitor/ios",
"@capacitor/cli": "file:../../node_modules/@capacitor/cli",
"@ionic/cli": "file:../../node_modules/@ionic/cli",
"@capacitor/app": "file:../../node_modules/@capacitor/app",
"@capacitor/haptics": "file:../../node_modules/@capacitor/haptics",
"@capacitor/keyboard": "file:../../node_modules/@capacitor/keyboard",
"@capacitor/splash-screen": "file:../../node_modules/@capacitor/splash-screen",
"@capacitor/status-bar": "file:../../node_modules/@capacitor/status-bar"
}
}
to get livereload working without being able to use the basically, we need to explicitly start the Angular dev server and tell our Capacitor to get its UI from there. I've opted to do this using the following packages:
in my root {
"scripts": {
"awesome-app:run:android": "run-s nx:awesome-app:build nx:awesome-app:run:android",
"awesome-app:run:ios": "run-s nx:awesome-app:build nx:awesome-app:run:ios",
"awesome-app:dev:android": "cross-env-shell CAPACITOR_LIVERELOAD=true \"run-p nx:awesome-app:serve nx:awesome-app:run:android\"",
"awesome-app:dev:ios": "cross-env-shell CAPACITOR_LIVERELOAD=true \"run-p nx:awesome-app:serve nx:awesome-app:run:ios\"",
"nx:awesome-app:run:android": "nx run awesome-app:run:android",
"nx:awesome-app:run:ios": "nx run awesome-app:run:ios",
"nx:awesome-app:build": "nx run awesome-app:build:development",
"nx:awesome-app:serve": "nx run awesome-app:serve"
}
}
next up, ensure that your application project has a import { CapacitorConfig } from '@capacitor/cli';
import { address } from 'ip';
const config: CapacitorConfig = {
// snip..
};
if (process.env['CAPACITOR_LIVERELOAD'] !== undefined) {
console.log('[CapacitorConfig] found process.env.CAPACITOR_LIVERELOAD:', process.env['CAPACITOR_LIVERELOAD']);
// this dynamic configuration allows the Capacitor app to source its UI from the Angular webserver,
// which will then serve the UI dynamically with live reloading for development purposes.
const serverIp = address();
const serverPort = process.env['PORT'] || '4200';
config.server = {
url: `http://${serverIp}:${serverPort}`,
cleartext: true,
};
console.log('[CapacitorConfig] effective config:', config);
} else {
Reflect.deleteProperty(config, 'server');
}
export default config; now open a terminal at your workspace root and execute
closing thoughts: with this in place, now should you have:
I will documented these steps more clearly in a I have also built up a great long list of questions from this process so far, but some of those need more research before the question can be completed... 🤣 so, we'll get there.. one day. |
Beta Was this translation helpful? Give feedback.
-
@ZaLiTHkA oh wow, that's great. Looking forward to the cleaned workspace to play with it. :-) |
Beta Was this translation helpful? Give feedback.
-
Hey everyone, So far this has worked perfectly. The plugins get copied to the native projects like they should. And I don't have to manage the dependency versions in the app package.json. My package.json in the apps folder now looks like this:
What do you think about that solution? Am I missing something why this would not work? |
Beta Was this translation helpful? Give feedback.
-
It's a mouthful but I think I've managed to create an Angular/Ionic app within my Nx 14 workspace (14.5.8 TBP) using
@nxext/ionic-angular
package.I've even managed to get my android project generated and shipped to an android device with
@nxext/capacitor
but, my Capacitor plugins don't work anymore (one of our own and the other one from capacitor-community -@capacitor-community/text-to-speech
).The thing is, it's all working when I build in my original project, outside of Nx workspace (so the usual way).
Is there some setting I'm forgetting here? Maybe I should explicitly specify my plugins somewhere in my
ionic.config.json
or something like that? Has anyone experienced something similar?PS I'm using nxext because that's the only extension compatible with Nx 14 (And I'm also using Angular 14). I wonder if the same problem would have happened if I were using
@nxtend/ionic-angular
and Nx 13?Beta Was this translation helpful? Give feedback.
All reactions