Titanium with genymotion

Author : lovecicy

Titanium是一个由Appcelerator提供的一个IDE,类似于PhoneGap,是一个一用JS编写移动应用的工具。

GenyMotion则是一个Android模拟器,用来代替官方的Android模拟器。

本文要介绍的是如何用Genymotion代替官方的Android模拟器,让Titanium的应用跑在Genymotion上,关于如何安装这两个程序,请参考各自的官网,这里不再赘述:

一、设置ADB环境变量

安装完Android SDK以后,需要设置ADB环境变量,可以在命令行中执行下面的命令,你也可以用窗口化的方式实现:

set ANDROID_PLATFORM_TOOLS="path\to\Android_SDK\sdk\platform-tools"
set ANDROID_TOOLS="path\to\Android_SDK\sdk\tools"
set path=%path%;%ANDROID_PLATFORM_TOOLS%;%ANDROID_TOOLS%

设置完以后在命令行中输入:adb。如果显示所有的adb命令则表示设置成功。

二、连接Genymotion

Genymotion已经有了Eclipse插件,但是Titanium目前还不支持,所以需要手动连接Genymotion和Titanium了。

这里要用到的是adb工具和Titanium CLI,Titanium CLI 应该在安装Titanium时自动安装了。

首先启动Genymotion上的模拟器,然后在命令行中输入下面的命令获取模拟器的ip:

adb devices

接下来,在另一个命令行中build我们的应用:

// normal Titanium app
titanium build --platform=android --build-only

// Alloy app
Alloy compile --config platform=android

最后,把应用安装到模拟器上:

adb -s 192.168.56.101:5555 install -r build/android/bin/app.apk

把其中的ip换成上面获取的ip地址,把后面的apk文件地址换成你的apk文件目录即可。

PS 如果在运行中碰到错误,请检查Titanium所需的所有软件及环境变量有没有配置。

Update:

今天在启动Genymotion模拟器的时候死活起不来,就报不能连接到虚拟设备,在SO上发现了解决办法(第二步解决了我的问题):

Step 1. Start VirtualBox, go to menu File/Preferences menu, go to Network section, select Host-only Networks tab.

If you don’t have any adapter defined, then you can create one (as indicated below) or you can ignore step 1 and Genymotion will create it when you try to start the VM.

If you do have an adapter there (vboxnet0) click the edit button. In the edit window, you must have DHCP server enabled AND the IP address and allocation pool of the server must be inside same network as the IP of the network controller. For example, I use:

  • IPv4 address/netmask: 192.168.56.1/255.255.255.0 (on Adapter tab)
  • DHCP server enabled checked (on DHCP server tab)
  • Server address/netmask: 192.168.56.100/255.255.255.0
  • Server lower/upper address: 192.168.56.100/192.168.56.254

Still in VirtualBox, select the Android VM you have, click Settings button, select Network section. In the Adapter 1 tab, you should have:

  • Enable network adapter checked
  • Attached to: Host-only adapter
  • Name: vboxnet0

Normally, if you have all these settings, it should work ok, but it didn’t for me. So I moved to step 2.

Step 2. As indicated by Genymotion, start VirtualBox, go to menu File/Preferences menu, go to Network section, select Host-only Networks tab and delete the defined adapters.

Start your VM in Genymotion. Genymotion will recreate the adapter with proper settings (as described in step 1)

Normally, if step 1 didn’t work for you, step 2 should work ok, but it didn’t for me. So I moved to step 3.

Step 3. Delete and recreate the Android VM in Genymotion (VirtualBox host-only network settings I left as described in step 1).

参考:

http://wizti.com/blog/genymotion-emulator/

error when build:

https://developer.appcelerator.com/question/157016/titanium-build—-error-spawn-enoent

windows software locations:

http://docs.appcelerator.com/titanium/3.0/#!/guide/Software_Locations_and_Environment_Variables-section-29004844_SoftwareLocationsandEnvironmentVariables-WindowsSoftwareLocations

standard

Have your say