titanium build failed(android)

今天在其他電腦裝titanium遇到以下錯誤:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[TRACE] Writing out AndroidManifest.xml
[ERROR] Exception occured while building Android project:
[ERROR] Traceback (most recent call last):
[ERROR] File "/home/sparrow/.titanium/mobilesdk/linux/3.1.0.GA/android/builder.py", line 2480, in <module>
[ERROR] builder.build_and_run(False, avd_id)
[ERROR] File "/home/sparrow/.titanium/mobilesdk/linux/3.1.0.GA/android/builder.py", line 2264, in build_and_run
[ERROR] self.manifest_changed = self.generate_android_manifest(compiler)
[ERROR] File "/home/sparrow/.titanium/mobilesdk/linux/3.1.0.GA/android/builder.py", line 1404, in generate_android_manifest
[ERROR] '-I', self.android_jar], warning_regex=r'skipping')
[ERROR] File "/home/sparrow/.titanium/mobilesdk/linux/3.1.0.GA/android/run.py", line 38, in run
[ERROR] print "[DEBUG] %s" % subprocess.list2cmdline(args_to_log)
[ERROR] File "/usr/lib/python2.7/subprocess.py", line 587, in list2cmdline
[ERROR] needquote = (" " in arg) or ("\t" in arg) or not arg
[ERROR] TypeError: argument of type 'NoneType' is not iterable

查了~/.titanium/mobilesdk/linux/3.1.0.GA/android/run.py這隻程式,發現有些參數是空的。

然後在androidsdk.py找到這段,功能是取得android sdk的aapt路徑:

1
2
3
4
5
6
7
8
9
def get_aapt(self):  
# for aapt (and maybe eventually for others) we
# want to favor platform-tools over android-x/tools
# because of new resource qualifiers for honeycomb
sdk_platform_tools_dir = self.get_sdk_platform_tools_dir()
if not sdk_platform_tools_dir is None and os.path.exists(os.path.join(sdk_platform_tools_dir, 'aapt')):
return os.path.join(sdk_platform_tools_dir, 'aapt')

return self.get_platform_tool('aapt')

比對另一台電腦sdk的platform-tools(舊):

1
2
3
4
5
6
7
8
9
10
11
12
13
|-- platform-tools
| |-- aapt
| |-- adb
| |-- aidl
| |-- api
| |-- dexdump
| |-- dx
| |-- fastboot
| |-- lib
| |-- llvm-rs-cc
| |-- NOTICE.txt
| |-- renderscript
| `-- source.properties

新下載的sdk:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
├── platform-tools
│ ├── adb
│ ├── api
│ ├── fastboot
│ ├── NOTICE.txt
│ └── source.properties
├── build-tools
│ └── 17.0.0
│ ├── aapt
│ ├── aidl
│ ├── dexdump
│ ├── dx
│ ├── lib
│ ├── llvm-rs-cc
│ ├── NOTICE.txt
│ ├── renderscript
│ └── source.properties

所以新版的sdk目錄結構有變動,在加上titanium執行檔案有預設路徑,解決方式有下列幾種:

  1. 修改androidsdk.py裡面的get_dx、get_dx_jar、get_aapt…回傳路徑
  2. 搬移檔案build-tools檔案到platform-tools
  3. 直接使用link

我使用直接採用link的方式:

1
2
3
4
5
6
cd ~/tool/android-sdk/platform-tools
ln -s ../build-tools/17.0.0/aapt
ln -s ../build-tools/17.0.0/dx
ln -s ../build-tools/17.0.0/dexdump
ln -s ../build-tools/17.0.0/llvm-rs-cc
ln -s ../build-tools/17.0.0/aidl

最後還要還要記得設定jarsigner、keytool:

1
2
3
4
sudo update-alternatives --install "/usr/bin/jarsigner" "jarsigner" "/usr/lib/jvm/java-6-sun/bin/jarsigner" 1
sudo update-alternatives --install "/usr/bin/keytool" "keytool" "/usr/lib/jvm/java-6-sun/bin/keytool" 1
sudo update-alternatives --config jarsigner
sudo update-alternatives --config keytool

weinre

weinre是一個用於瀏覽器的遠端除錯工具,運作方式與jsconsole相同,都是透過include一隻外部js script,來與server溝通傳遞資料。但是jsconsole只提供一些很基本功能,如果要能像chrome一樣,查看dom element、network等功能,可以使用weinre

使用時機:

使用android、ios等手持裝置的browser,或者對IE除錯的時候,都很適合。

weinre原理:

weinre基本原理是,建立一個console page,然後經由weinre server,與development page(你要除錯的page)互相傳遞資料溝通。( 溝通方式採用long polling)

時序圖如下:

 
透過node.js安裝:
sudo npm install -g weinre
操作流程:

開啟weinre server:

weinre --httpPort 8081 --boundHost localhost

打開瀏覽器輸入http://localhost:8081/

然後在你想要除錯的頁面加上以下script:

<script src="http://localhost:8081/target/target-script-min.js#anonymous"></script>

例如:

<!DOCTYPE HTML>                                                                                  
<html lang="en">                                                                                 
<head>                                                                                           
    <meta charset="UTF-8">                                                                       
    <title></title>                                                                              
    <script src="http://localhost:8081/target/target-script-min.js#anonymous"></script>       
</head>                        
<body>                                                                                           
    <div>weinre test</div>                                                                       
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
</body>                                                                                          
</html>                                                                                          

開啟http://localhost:8081/client/#anonymous,就可以開始除錯了。