Quotes application for Web and Mobile (Android, iOS) with single code base buit with Angular and Nativescript.
You can check previews and screenshots of this application for Web, Android and iOS platforms at ngxp.io
- Globally installed Nativecript -
npm install -g nativescript
- Globally installed Angular CLI -
npm install -g angular-cli
- Mac OS to build iOS app.
git clone https://github.com/shripalsoni04/ngxp-quotes-app.git
cd ngxp-quotes-app
npm run ngxp-install
- As we are using nativescript-firebase plugin, just press y for below two questions when asked while installation.
- are you using iOS?
- are you using android?
- For all other questions press n.
- As we are using nativescript-firebase plugin, just press y for below two questions when asked while installation.
npm start
- This will start the application at http://localhost:4200.
- First start the simulator or connect the iOS device.
- Execute
npm run start.ios
- Note - If you are using XCode8 then you need to set the DEVELPMENT_TEAM. There are two ways to set it.
- Using XCode
- After executing
npm run start.ios
command, open project wordspace file nativescript/platforms/ios/nativescript.xcworkspace in XCode - Click on nativescript project in XCode and set Team from General Tab.
- The issue with thie approach is, you need to set it everytime you remove and add the iOS platform.
- After executing
- From build.xconfig (preferable)
- Open nativescript/app/App_Resources/iOS/build.xconfig file.
- Uncomment
DEVELOPMENT_TEAM = YOUR_TEAM_ID;
line, and enter your team id.
- Using XCode
- As we are using nativescript firebase plugin in the project, we need to perform below two steps before starting app on android.
-
Copy
nativescript/app/App_Resources/Android/google-services.json
toplatforms/android
folder. -
Changes in
nativescript/platforms/android/build.gradle
file.Near the top there's a dependencies section, add classpath "com.google.gms:google-services:3.0.0" so it becomes something like:
dependencies { classpath "com.android.tools.build:gradle:X.X.X" classpath "com.google.gms:google-services:3.0.0" }
At the very bottom of the same file add
apply plugin: "com.google.gms.google-services"
-
Now execute
npm run start.android
-
You can execute any valid command of angular-cli from web/
folder and any valid command of nativescript-cli from nativescript/
folder.
For convenince below are the commands which you can execute from root directory.
Command | Description |
---|---|
npm run ngxp-install | Installs dependencies of web and nativescript applications. Creates symlink of x-shared folder in both web and nativescript project. |
Command | Description |
---|---|
npm start | Starts web application at http://localhost:4200 |
npm run start.prod | Starts web application in production mode. Runs uglification and minification. |
npm run start.aot | Performs AOT for web application templates and starts web application. (Before executing this command refer Point 1 of Known Issues) |
npm run start.aot.prod | Performs AOT, minification, uglification and starts web application. (Before executing this command refer Point 1 of Known Issues) |
npm run build | Builds the web application and copy the built project in web/dist folder. |
npm run build.prod | Builds the web application in production mode and copy the built project in web/dist folder. |
npm run build.aot | Performs AOT, build the project and then copy the built project in web/dist folder. |
npm run build.aot.prod | Performs AOT, prepares production build and then copy the built project in web/dist folder. |
npm test | Runs web application and x-shared unit test cases. It will not generate code coverage report. |
npm run test-cc | Runs web application and x-shared unit test cases and generates code coverage report. |
Command | Description |
---|---|
npm run start.ios | Runs application on iOS emulator/device |
npm run start.android | Runs application on Android emulator/device |
npm run livesync.ios | Starts application in livesync mode on iOS emulator/device. |
npm run livesync.android | Starts application in livesync mode on Android emulator/device. |
- Regarding AOT
- When you prepare aot build or serve project in aot mode, make sure you comment the exclude configuration in web/src/tsconfig.json file. Because currently AOT build also trying to compile test files and failing .This is know issue and can be tracked at angular/angular-cli#2736. Once it is resolved, we can keep this uncommented for better unit testing support.
// "exclude": [
// "**/*.spec.ts",
// "testing/**/*.ts"
// ]
- Note: When you execute
npm test
ornpm run test-cc
commands, make sure you uncomment above lines, otherwise test cases will give errors.
- Angular dependencies at two levels for AOT support
-
Currently we have added angular dependencies in root level package.json and web/package.json. Because, AOT does not work properly when we use path mapping and this issue is reported and can be traked at angular/angular-cli#1732 and PR:angular/angular-cli#2470. Once this issue is resolved we can add path mapping as shown below and remove the angular dependencies from web/package.json, so in case of any version update we just need to change the version at root directory level.
web/src/tsconfig.json
"paths": { "@angular/*": ["../../node_modules/@angular/*"] }
- nativescript-cardview
- nativescript-floatingactionbutton
- nativescript-iqkeyboardmanager
- nativescript-material-icons
- nativescript-ng2-fonticon
- nativescript-plugin-firebase
- nativescript-social-share
- nativescript-swiss-army-knife
- nativescript-theme-core
- angular2-mdl
- Awesome framework and toolchain of Nativescript and Angular.
- A starter project to quickly create your own cross platform application for web and native mobile platform similar to this application.
- A blog post explaining the folder structure of this application.