nativescript在ubuntu16.04-desktop安装

kevin.Zhu 发布于:2018-1-26 17:21 分类:文摘  有 19 人浏览,获得评论 0 条  

http://blog.programster.org/ubuntu-16-04-setting-up-nativescript


http://blog.programster.org/set-up-android-emulator

nativescript第一个运行例子: https://docs.nativescript.org/tutorial/chapter-1#11-install-nativescript-and-configure-your-environment


-------------------------------------------------

Install Prerequisite

Install node 6.x LTS.


If you are running on a 64-bit system, install the runtime libraries for the ia32/i386 architecture.

sudo apt-get install lib32z1 lib32ncurses5 libbz2-1.0:i386 libstdc++6:i386 
	

Install the g++ compiler (you probably already have it)

sudo apt-get install g++ 
	

Install JDK 8 or a later stable official release. I recommend using the webupd8 repo rather than openjdk.


Download the command line tools for android, which should be at the bottom of this page).

wget https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip 
	

Put the zip into a folder called android where you want to keep it before then extracting the zip file:

mkdir $HOME/android
mv sdk-tools-linux-*.zip $HOME/android/.
cd $HOME/android/
unzip sdk-tools-linux-* 
	

Set android home and update your PATH. So you don't have to keep doing this manually, add these to your $HOME/.bashrc file.

export ANDROID_HOME=$HOME/android
export PATH=${PATH}:$ANDROID_HOME/tools
export PATH=${PATH}:$ANDROID_HOME/tools/bin
export PATH=${PATH}:$ANDROID_HOME/platform-tools 
	

Update the ownership of these files to be owned by you.

sudo chown $USER:$USER -R $ANDROID_HOME 
	

Install all packages for the Android SDK Platform 25, Android SDK Build-Tools 25.0.2 or later, Android Support Repository, Google Repository and any other SDKs that you may need. You can alternatively use the following command, which will install all required packages.

sudo $ANDROID_HOME/tools/bin/sdkmanager "tools" "platform-tools" "platforms;android-25" "build-tools;25.0.2" "extras;android;m2repository" "extras;google;m2repository" 
	

This may take a while and won't show any progress status whilst its working away.

Install Nativescript CLI

Install the nativescript CLI You have a choice here, you can either run:

sudo npm install -g nativescript 
	

Then get an ugly permission error fly past stating that

EACCES: permission denied, mkdir '/home/$USER/.local/share/.nativescript-cli' 
	

... which can be resolved by running:

tns doctor 
	

... or you could just run:

sudo npm install -g --unsafe-perm nativescript 
	

If you don't use sudo, you will get the following error message: Missing write access to /usr/lib/node_modules.

Check Setup

You should now be able to check that everything installed correctly by running tns doctor, which should output:

NOTE: You can develop for iOS only on Mac OS X systems.
To be able to work with iOS devices and projects, you need Mac OS X Mavericks or later.

Your components are up-to-date: 
nativescript,tns-core-modules,tns-android,tns-ios

No issues were detected. 
	

Conclusion

You've now installed Nativescript. You now probably want to set up an emulator before then building your first app.



###############################################################################


After having set up Nativescript, you probably want to set up an emulator for testing your apps.

Steps

You can run the command below to list your available android devices and emulators:

tns device android --available-devices 
		

After a fresh installlation, you will probably have nothing, with the following output:

 Available emulators
┌─────────────┬──────────┬─────────┬───────────────────┐
│ Device Name │ Platform │ Version │ Device Identifier │
└─────────────┴──────────┴─────────┴───────────────────┘

Connected devices & emulators
Searching for devices...
Cannot find connected devices. Reconnect any connected devices, verify that your system recognizes them, and run this command again. 
		

The steps below will get you set up with an android emulator for version 6.0.This will not work inside a Virtualbox machine, or whilst Virtualbox, docker, or other virtualization software is running. More info.

Steps

First we need to create a new Android virtual device (AVD). To do this, we need to download an image for it to use (you only have to do this once)

sdkmanager "system-images;android-23;google_apis;x86" 
		

Now create as many virtual devices as you want:

avdmanager create avd --name $name --package "system-images;android-23;google_apis;x86" 
		

For example:

avdmanager create avd --name test --package "system-images;android-23;google_apis;x86" 
		

Now if you run avdmanager list avd you should see:

Available Android Virtual Devices:
    Name: test
    Path: /home/stuart/.android/avd/test.avd
  Target: Google APIs (Google Inc.)
          Based on: Android 6.0 (Marshmallow) Tag/ABI: google_apis/x86 
		

Now we can run our emulator to see it working:

cd $ANDROID_HOME/tools
emulator -avd test 
		

You should see your new emulator: