Difference between revisions of "User:Saul/nativescript"
m (→npm) |
(→npm) |
||
Line 93: | Line 93: | ||
npm i nativescript-google-maps-sdk | npm i nativescript-google-maps-sdk | ||
cp -r node_modules/nativescript-google-maps-sdk/platforms/android/res/values template/app/App_Resources/Android # copy string templates over | cp -r node_modules/nativescript-google-maps-sdk/platforms/android/res/values template/app/App_Resources/Android # copy string templates over | ||
+ | </source> | ||
+ | Then edit '''template/app/App_Resources/Android/values/nativescript_google_maps_api.xml''':<br> | ||
+ | <source> | ||
+ | Remove the comment tags | ||
+ | Replace "PUT_API_KEY_HERE" with you api key | ||
</source> | </source> | ||
Revision as of 23:25, 9 July 2018
Nativescript is a framework for building native ios and android apps.
Nativescript and vue tutorial
Contents
Setup
Firstly ensure that npm is installed.
npm install -g nativescript # Install the nativescript cli
Android
Install
# Install dependencies
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 libstdc++6:i386 # Install dependencies
# OR (If you encounter an error showing "Unable to locate package lib32bz2-1.0")
sudo apt-get install lib32z1 lib32ncurses5 libbz2-1.0:i386 libstdc++6:i386
sudo apt-get install g++ # Install the g++ compiler
# Install JDK8/10
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
# OR JDK10 (not currently working)
# sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt install oracle-java8-installer
# OR JDK10 (not currently working)
# sudo apt install oracle-java10-installer
# Set the ENV varible
export JAVA_HOME=$(update-alternatives --query javac | sed -n -e 's/Best: *\(.*\)\/bin\/javac/\1/p')
Download the android sdk tools from https://developer.android.com/studio/#downloads
Extract it in ~/android/sdk
export ANDROID_HOME=~/android/sdk # Set the ANDROID_HOME ENV varible
# Install dependencies
sudo $ANDROID_HOME/tools/bin/sdkmanager "tools" "platform-tools" "platforms;android-25" "build-tools;27.0.3" "extras;android;m2repository" "extras;google;m2repository"
Install Emulator
IOS
To build for IOS you will need a machine running MacOS.
Nativescript MacOS install docs
Webpack Template
Using npm
vue init nativescript-vue/vue-cli-template <project-name>
cd <project-name>
npm install
Using tns
Note: Then tns vue template only supports js files - no vue files.
tns create MyApp --template nativescript-vue-template
cd MyApp
tns run android # run live
tns build android
Project Structure
nativescript-vue/vue-cli-template
dist
The dist/ directory is the directory that nativescript builds the app into.
The built app can be found in dist/platforms/app/build/outputs/apk/debug/app-debug.apk
template
The template/ directory holds the data for the android application like the AndroidManifest.
Usage
Maps
Install
tns
tns plugin add nativescript-google-maps-sdk # install the maps plugin
cp -r node_modules/nativescript-google-maps-sdk/platforms/android/res/values app/App_Resources/Android/src/main/res # copy string templates over
Then edit app/App_Resources/Android/src/main/res/values/nativescript_google_maps_api.xml:
Remove the comment tags
Replace "PUT_API_KEY_HERE" with you api key
Insert before the closing application tag in :
<meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/nativescript_google_maps_api_key" />
npm
npm i nativescript-google-maps-sdk
cp -r node_modules/nativescript-google-maps-sdk/platforms/android/res/values template/app/App_Resources/Android # copy string templates over
Then edit template/app/App_Resources/Android/values/nativescript_google_maps_api.xml:
Remove the comment tags
Replace "PUT_API_KEY_HERE" with you api key
Usage
You must use the namespace on the pages you wish to use the map on, do this by editing the page tag like so:
<page xmlns:maps="nativescript-google-maps-sdk">
<!-- Page content. -->
</page>
Then you can use the maps tag like so:
<maps:mapView latitude="{{ -36 }}" longitude="{{ 174 }}" />