之前使用 vysor 投影 Android 裝置到 Ubuntu 桌面。但可能是 chromium 沒有更新,所以一直出現 plugin not support 之類的訊息。
爬文建議使用 scrcpy。
官方教學,https://github.com/Genymobile/scrcpy
也參考這篇,https://www.linuxuprising.com/2019/03/control-android-devices-from-your.html
實際安裝步驟有點麻煩。
1. 安裝必要套件
$ sudo apt install adb ffmpeg libsdl2-2.0-0 make gcc pkg-config meson ninja-build libavcodec-dev libavformat-dev libavutil-dev libsdl2-dev
2. 用 pip 安裝 meson 和 ninja
$ sudo pip3 install meson ninja
3. 下載 scrcpy-server,並改名為 scrcpy-server*.jar
https://github.com/Genymobile/scrcpy/releases/download/v1.16/scrcpy-server-v1.16
4. 將 scrcpy 加到某目錄
$ sudo install scrcpy-server-v*.jar /usr/local/bin/scrcpy-server.jar
5. 下載 scrcpy source,目前我是裝 1.16
https://github.com/Genymobile/scrcpy/releases/tag/v1.16
6. 解開目錄後進入 scrcpy 編譯
$ meson build --buildtype release --strip -Db_lto=true -Dprebuilt_server=../scrcpy-server-v1.16.jar
$ cd build
$ ninja
$ sudo ninja install
之後應該就可以用 scrcpy 或是 sudo scrcpy 投影啦~
2020年8月15日 星期六
2018年10月15日 星期一
2016年11月6日 星期日
[Android] AndroidScreencast
因為 ubuntu 版本是 10.04 LTS 太舊了, 所以一堆問題要解決
要把 Android 的畫面打到 ubuntu 應該要有一堆方法, 記得之前用 Droid@Screen, 可是現在不知道怎麼了不能用
後來又看到 AndroidScreencast, 雖然感覺有點慢也將就著用吧
$ git clone https://github.com/xSAVIKx/AndroidScreencast
$ cd AndroidScreencast
$ mvn package
馬上報錯, 因為沒有裝 maven
$ sudo apt-get install maven2
結果軟體最低限制 Java 7 and Maven 3.2.5, 只好想辦法裝 maven3
因為沒有 apt, 只好抓 binary, 參考這篇文章, 可是現在只剩下 maven-3.2.2, 就加減用吧
再來是修改環境變數 JAVA_HOME, M2_HOME, MAVEN_HOME, M2 一堆
修改完還要把 maven2 移除掉才行
$ sudo apt-get autoremove maven2
確認版本
$ mvn -v
Apache Maven 3.2.2
終於可以編譯了
$ mvn package
編譯完成後執行發現又錯, 錯誤訊息在 app.properties, 要把
最後終於可以執行了
$ java -jar target/androidscreencast-0.0.7s-executable.jar
唉, 舊版本就是該死
要把 Android 的畫面打到 ubuntu 應該要有一堆方法, 記得之前用 Droid@Screen, 可是現在不知道怎麼了不能用
後來又看到 AndroidScreencast, 雖然感覺有點慢也將就著用吧
$ git clone https://github.com/xSAVIKx/AndroidScreencast
$ cd AndroidScreencast
$ mvn package
馬上報錯, 因為沒有裝 maven
$ sudo apt-get install maven2
結果軟體最低限制 Java 7 and Maven 3.2.5, 只好想辦法裝 maven3
因為沒有 apt, 只好抓 binary, 參考這篇文章, 可是現在只剩下 maven-3.2.2, 就加減用吧
再來是修改環境變數 JAVA_HOME, M2_HOME, MAVEN_HOME, M2 一堆
修改完還要把 maven2 移除掉才行
$ sudo apt-get autoremove maven2
確認版本
$ mvn -v
Apache Maven 3.2.2
終於可以編譯了
$ mvn package
編譯完成後執行發現又錯, 錯誤訊息在 app.properties, 要把
adb.path=adb.exe改為
adb.path=adb記得 adb 也要 export 到環境變數, 我是用鳥鳥的 appinventor 帶的 adb
最後終於可以執行了
$ java -jar target/androidscreencast-0.0.7s-executable.jar
唉, 舊版本就是該死
2011年11月22日 星期二
2011年8月8日 星期一
[Android] htcDev
我lag了嗎?
今年六月HTC在Uplinq 2011的keynote宣佈要開放SenseUI的SDK,不過今天我才發現可以下載了... 目前還有unlock的bootloader和kernel source,未來應該會提供更多的資源吧,例如他們的app?
今年六月HTC在Uplinq 2011的keynote宣佈要開放SenseUI的SDK,不過今天我才發現可以下載了... 目前還有unlock的bootloader和kernel source,未來應該會提供更多的資源吧,例如他們的app?
2011年2月21日 星期一
[Android] Install an App in Android
1.從Android外部安裝
2.從Android內部安裝
3.從Android外部上傳後,由系統(PackageManager)啟動時自行安裝
reference: What does `adb install' do under the hood?
foobar@ubuntu:~$ adb install app.apk將安裝到/data/app目錄下,並建立{yourapp.package.main}目錄
2.從Android內部安裝
foobar@ubuntu:~$ adb shell將安裝到/data/app目錄下,並建立yourapp.package.main目錄
# pm install /path/to/app.apk
3.從Android外部上傳後,由系統(PackageManager)啟動時自行安裝
foobar@ubuntu:~$ adb push app.apk [/data/app | /system/app]如果push到/system/app下,則無法透過系統設定中的Manage applications移除,如果push到/data/app下,使用者可移除該app
reference: What does `adb install' do under the hood?
2011年1月11日 星期二
[Android] Compile Android module
1.add environment variables
2.using mmm to compile module under root path
2.or using mm to compile module under module path
2.or using make to compile module under root path
$ cd /path/to/android
$ cd build
$ . envsetup.sh
$ help
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment: - croot: Changes directory to the top of the tree. - m: Makes from the top of the tree. - mm: Builds all of the modules in the current directory. - mmm: Builds all of the modules in the supplied directories. - cgrep: Greps on all local C/C++ files. - jgrep: Greps on all local Java files. - resgrep: Greps on all local res/*.xml files. - godir: Go to the directory containing a file. Look at the source to view more functions. The complete list is: add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant cproj croot findmakefile gdbclient get_abs_build_var getbugreports get_build_var getprebuilt gettop godir help isviewserverstarted jgrep lunch m mm mmm pid printconfig print_lunch_menu resgrep runhat runtest setpaths set_sequence_number set_stuff_for_environment settitle smoketest startviewserver stopviewserver systemstack tapas tracedmdump
2.using mmm to compile module under root path
$ cd /path/to/android
$ mmm external/ping
============================================ PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=2.2.1 TARGET_PRODUCT=generic TARGET_BUILD_VARIANT=eng TARGET_SIMULATOR= TARGET_BUILD_TYPE=release TARGET_BUILD_APPS= TARGET_ARCH=arm HOST_ARCH=x86 HOST_OS=linux HOST_BUILD_TYPE=release BUILD_ID=MASTER ============================================ target Non-prelinked: ping (out/target/product/generic/symbols/system/bin/ping) Install: out/target/product/generic/system/bin/ping
2.or using mm to compile module under module path
$ cd /path/to/android
$ cd development/samples/NotePad
$ mm
============================================ PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=2.2.1 TARGET_PRODUCT=generic TARGET_BUILD_VARIANT=eng TARGET_SIMULATOR= TARGET_BUILD_TYPE=release TARGET_BUILD_APPS= TARGET_ARCH=arm HOST_ARCH=x86 HOST_OS=linux HOST_BUILD_TYPE=release BUILD_ID=MASTER ============================================ Copying: out/target/common/obj/APPS/NotePad_intermediates/classes-full-debug.jar Install: out/target/product/generic/system/app/NotePad.apk Copying: out/target/common/obj/APPS/NotePadTests_intermediates/classes-full-debug.jar Install: out/target/product/generic/data/app/NotePadTests.apk
2.or using make to compile module under root path
$ cd /path/to/android
$ make Phone
PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=2.2.1 TARGET_PRODUCT=generic TARGET_BUILD_VARIANT=eng TARGET_SIMULATOR= TARGET_BUILD_TYPE=release TARGET_BUILD_APPS= TARGET_ARCH=arm HOST_ARCH=x86 HOST_OS=linux HOST_BUILD_TYPE=release BUILD_ID=MASTER ============================================ Install: out/host/linux-x86/bin/aapt Install: out/host/linux-x86/bin/aidl Copying: out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes-full-debug.jar Install: out/host/linux-x86/framework/dx.jar Install: out/host/linux-x86/bin/dx Copying: out/target/common/obj/JAVA_LIBRARIES/ext_intermediates/classes-full-debug.jar Copying: out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes-full-debug.jar Copying: out/target/common/obj/APPS/Phone_intermediates/classes-full-debug.jar Install: out/host/linux-x86/framework/signapk.jar Install: out/host/linux-x86/bin/zipalign target Package: Phone (out/target/product/generic/obj/APPS/Phone_intermediates/package.apk) 'out/target/common/obj/APPS/Phone_intermediates/classes.dex' as 'classes.dex'... Install: out/target/product/generic/system/app/Phone.apk
2011年1月6日 星期四
[Android] Create a fake character device driver
1.download Android kernel, details in here
2.get the current kernel configuration from the emulator
3.modify .config file
4.modify kernel Makefile
5.compile kernel
6.get kernel image
7.create fake driver, devone.c
8.write fake driver Makefile
9.compile kernel module
10.start the emulator with our kernel
11.put busybox into emulator
12.put ko into emulator
13.insert kernel module in emulator
14.check the major number of devone
15.insert the device node of devone
reference:
* 實作一個假的character driver 在emulator上跑
* Writing your first kernel module
2.get the current kernel configuration from the emulator
$ adb pull /proc/config.gz .
$ gunzip config.gz
$ mv config .config
3.modify .config file
$ vim .config
CONFIG_MODULES=y
4.modify kernel Makefile
$ vim Makefile
# Use --build-id when available. #LDFLAGS_BUILD_ID = $(patsubst -Wl$(comma)%,%,\ # $(call ld-option, -Wl$(comma)--build-id,))
5.compile kernel
$ make mrproper
$ sudo make ARCH=arm CROSS_COMPILE={/path/to/android}/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-
6.get kernel image
Kernel: arch/arm/boot/Image is ready Kernel: arch/arm/boot/zImage is ready
7.create fake driver, devone.c
#include <linux/init.h> #include <linux/module.h> #include <linux/types.h> #include <linux/kernel.h> #include <linux/fs.h> #include <linux/cdev.h> #include <asm/uaccess.h> MODULE_LICENSE("Dual BSD/GPL"); static int devone_devs = 1; /* device count */ static int devone_major = 0; /* dynamic allocation */ static int devone_minor = 0; static struct cdev devone_cdev; ssize_t devone_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos) { int i; unsigned char val = 0xff; int retval; for (i = 0 ; i < count ; i++) { if (copy_to_user(&buf[i], &val, 1)) { retval = -EFAULT; goto out; } } retval = count; out: return (retval); } struct file_operations devone_fops = { .read = devone_read, };
8.write fake driver Makefile
KERNELDIR={/path/to/android}/kernel PWD := $(shell pwd) obj-m := devone.o modules: make -C $(KERNELDIR) M=$(PWD) modules clean: rm -rf *.o *~ core.depend .*.cmd *.ko *.mod.c .tmp_versions modules.* Module*
9.compile kernel module
$ sudo make ARCH=arm CROSS_COMPILE={/path/to/android}/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-
10.start the emulator with our kernel
$ emulator -avd {name} -partition-size {number} -kernel {/path/to/kernel/zImage}
11.put busybox into emulator
$ adb push busybox /system/bin
$ adb shell chmod 755 /system/bin/busybox
12.put ko into emulator
$ adb remount
$ adb push devone.ko /system/lib
13.insert kernel module in emulator
$ adb shell
# insmod devone.ko
# lsmod
devone 1784 - - Live 0xbf000000
14.check the major number of devone
# cat /proc/devices
... 136 pts 252 devone 253 ttyS ...
15.insert the device node of devone
# /system/bin/busybox mknod /dev/devone c 252 0
# /system/bin/busybox ls /dev/
... device-mapper tty20 tty51 devone tty21 tty52 eac tty22 tty53 ...
# /system/bin/busybox ls -al /dev/devone
crw-rw-rw- 1 0 0 252, 0 Jan 4 05:33 /dev/devone
reference:
* 實作一個假的character driver 在emulator上跑
* Writing your first kernel module
2010年11月27日 星期六
[Android] Install Android market in Android emulator 2.2
使用SDK下載回來的avd:
1.Download Android market apk
使用自己編出來的system.img:
1.直接安裝Vending.apk和GoogleServicesFramework.apk就好了
reference:
* [Android]在SDK 2.2模擬器中安裝Market
1.Download Android market apk
$ wget http://goo.gl/dz3ZB2.Create froyo AVD
$ android create avd --target 8 --name froyo3.Start emulator
$ emulator -avd froyo -partition-size 963.Modified build.prop and comment "ro.config.nocheckin=yes"
$ adb pull /system/build.prop
$ vim build.prop
#ro.config.nocheckin=yes4.Restore to system
$ adb remount /system5.Remove SdkSetup.apk
$ adb push build.prop /system
$ adb shell rm /system/app/SdkSetup.apk6.Shut down the emulator
$ adb push GoogleServicesFramework.apk /system/app
$ adb push Vending.apk /system/app
$ adb reboot7.Remove emulator image
$ cd /path/to/avd8.Restart emulator
$ rm userdata-qemu.img userdata.img cache.img
使用自己編出來的system.img:
1.直接安裝Vending.apk和GoogleServicesFramework.apk就好了
$ adb install GoogleServicesFramework.apk2.Restart emulator
$ adb install Vending.apk
reference:
* [Android]在SDK 2.2模擬器中安裝Market
2010年11月22日 星期一
[Android] Build Android bootchart
bootchart是一套可視覺化分析GNU/Linux啟動過程的工具,它可蒐集啟動的資訊,並產生PNG/SVG/EPS等格式的圖檔,提供我們做進一步的效能分析,以下簡述安裝過程:
1.安裝bootchart工具
2.重新編譯init(讓init支援bootchart)
切換到Android source code目錄下
3.重新啟動機器
4.重新開機完成後檢視是否有紀錄
5.下載開機紀錄
6.產生bootchart.tgz
7.產生bootchart圖檔
如果沒有/usr/share/bootchar/bootchart.jar這個檔案,可以在這裡取得source,解開後執行ant將會編出bootchart.jar
reference:
* Build Android Bootchart
* Using Bootchart on Android
1.安裝bootchart工具
$ sudo apt-get install bootchart
2.重新編譯init(讓init支援bootchart)
切換到Android source code目錄下
$ cd /path/to/android改變init系統時間
$ touch system/core/init/init.c載入Android bash工具
$ . build/envsetup.sh編譯init模組
$ m INIT_BOOTCHART=true啟動機器
$ emulator -system {/path/to}/system.img -data {/path/to}/userdata.img -ramdisk {/path/to}/ramdisk.img設定init的time out
$ adb shell 'echo 180 > /data/bootchart-start'
$ adb shell 'mkdir /data/bootchart'
3.重新啟動機器
$ adb reboot
4.重新開機完成後檢視是否有紀錄
$ adb shell ls /data/bootchart
header kernel_pacct proc_diskstats.log proc_ps.log proc_stat.log
5.下載開機紀錄
$ cd /whatever/path
$ adb pull /data/bootchart/header
$ adb pull /data/bootchart/kernel_pacct
$ adb pull /data/bootchart/proc_diskstats.log
$ adb pull /data/bootchart/proc_ps.log
$ adb pull /data/bootchart/proc_stat.log
6.產生bootchart.tgz
$ {path/to/android}/system/core/init/grab-bootchart.sh
7.產生bootchart圖檔
$ java -jar /usr/share/bootchart/bootchart.jar bootchart.tgz
Parsing /tmp/android-bootchart/bootchart.tgz Wrote image: ./bootchart.png
如果沒有/usr/share/bootchar/bootchart.jar這個檔案,可以在這裡取得source,解開後執行ant將會編出bootchart.jar
reference:
* Build Android Bootchart
* Using Bootchart on Android
2010年11月20日 星期六
[Android] Modify ramdisk.img on Android
ramdisk.img
system.img
userdata.img
Here is the steps:
1.Change directory to whatever/path
gunzip options:
cpio options:
reference:
* Android ramdisk.img system.img userdata.img
* android ramdisk的壓縮與解壓縮
A small partition image with gzipped cpio archive that is mounted read-only by the kernel at boot time. It only contains /init and a few config files. It is used to start init which will mount the rest of the system images properly and run the init procedure. A Ramdisk is a standard Linux feature.
system.img
A partition image that will be mounted as /system and thus contains all system binaries
userdata.img
A partition image that can be mounted as /data and thus contains all application-specific and user-specific data.
Here is the steps:
1.Change directory to whatever/path
$ cd whatever/path2.Copy the original ramdisk.img
$ cp /path/to/ramdisk.img .3.Create a temporary folder, say ramdisk-ext
$ mkdir ramdisk-ext4.Change directory to ramdisk-ext
$ cd ramdisk-ext5.Extract the ramdisk.cpio in the ramdisk-ext folder
$ gunzip -dcv ../ramdisk.img | cpio -idm6.Check out the directories in ramdisk.img
$ ls
data dev init.goldfish.rc proc sys default.prop init init.rc sbin system7.Do some modifications
$ touch foo8.Recreate the ramdisk.cpio
$ mkdir bar
$ find . | cpio -H newc -o | gzip -9 >../ramdisk.img9.Start the emulator
$ emulator -system system.img -data userdata.img -ramdisk ramdisk.img10.Check out the directories in the emulator
$ adb shell ls -l
drwxrwxrwt root root 2010-11-26 16:54 sqlite_stmt_journals drwxrwx--- system cache 2010-11-26 16:54 cache d--------- system system 2010-11-26 16:54 sdcard lrwxrwxrwx root root 2010-11-26 16:54 etc -> /system/etc drwxr-xr-x root root 2010-11-15 07:33 system drwxr-xr-x system system 2010-11-26 16:53 bar drwxr-x--- system system 2010-11-26 16:52 sbin -rwxr-x--- system system 1677 1970-01-01 00:00 init.goldfish.rc dr-xr-xr-x root root 1970-01-01 00:00 proc -rw-r--r-- system system 0 2010-11-26 16:52 foo -rwxr-x--- system system 106696 1970-01-01 00:00 init -rwxr-x--- system system 10700 1970-01-01 00:00 init.rc drwxr-xr-x root root 1970-01-01 00:00 sys -rw-r--r-- system system 118 1970-01-01 00:00 default.prop drwxrwx--x system system 2010-11-16 09:04 data drwx------ root root 2009-08-07 03:35 root drwxr-xr-x root root 2010-11-26 16:54 dev
gunzip options:
-c, --stdout write on standard output, keep original files unchanged -d, --decompress decompress -v, --verbose verbose mode -1, --fast compress faster -9, --best compress better
cpio options:
-i, --extract Extract files from an archive (run in copy-in mode) -d, --make-directories Create leading directories where needed -m, --preserve-modification-time Retain previous file modification times when creating files -H, --format=FORMAT Use given archive FORMAT -c Use the old portable (ASCII) archive format -o, --create Create the archive (run in copy-out mode) -v, --verbose Verbosely list the files processed -B Set the I/O block size to 5120 bytes -u, --unconditional Replace all files unconditionally Examples: cpio -covB > [file|device]<== Backup cpio -icduv < [file|device]<== Restore "-H newc" use the new (SVR4) portable format. If you wish the old portable (ASCII) archive format, use "-H odc" instead.
reference:
* Android ramdisk.img system.img userdata.img
* android ramdisk的壓縮與解壓縮
[Android] 在Android shell以Dalvik VM執行Java應用程式
由於Android上的Java程式需要在Dalvik VM下才能執行,因此Android上的App就是透過Zygote去fork出child process去執行,但如果我們希望可以直接在Android的shell下執行Java應用程式,需要一些小技巧
1.撰寫Java測試程式HelloWorld.java
2.編譯HelloWorld.java
3.將dx設在環境變數路徑
4.以dx工具將bytecode轉成Dalvik executable format(.dex)格式的jar
5.上傳到模擬器
6.在Android shell下執行
1.撰寫Java測試程式HelloWorld.java
// // HelloWorld.java // public class HelloWorld { public static void main(String args[]) { System.out.println("Hello World!!\n"); } }
2.編譯HelloWorld.java
$ javac HelloWorld.java
3.將dx設在環境變數路徑
$ export PATH={path/to/sdk}/platforms/{android-platform-number}/tools:$PATH
4.以dx工具將bytecode轉成Dalvik executable format(.dex)格式的jar
$ dx --dex --output=helloworld.jar HelloWorld.class
5.上傳到模擬器
$ adb push helloworld.jar /data
6.在Android shell下執行
$ adb shell
# /system/bin/dalvikvm -cp /data/helloworld.jar HelloWorld
Hello World!!
2010年11月10日 星期三
[Tips] Run Android application from command line
syntax:
example:
usage:
reference: Run Android Application from Command Line
# am start -a android.intent.action.MAIN -n package/class_fullname
example:
# am start -a android.intent.action.MAIN -n my.demo/my.demo.HelloWorld
usage:
usage: am [subcommand] [options] start an Activity: am start [-D] [-W]-D: enable debugging -W: wait for launch to complete start a Service: am startservice send a broadcast Intent: am broadcast start an Instrumentation: am instrument [flags] -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT) -e : set argument to -p : write profiling data to -w: wait for instrumentation to finish before returning start profiling: am profile start stop profiling: am profile stop specifications include these flags: [-a ] [-d ] [-t ] [-c [-c ] ...] [-e|--es ...] [--esn ...] [--ez ...] [-e|--ei ...] [-n ] [-f ] [--grant-read-uri-permission] [--grant-write-uri-permission] [--debug-log-resolution] [--activity-brought-to-front] [--activity-clear-top] [--activity-clear-when-task-reset] [--activity-exclude-from-recents] [--activity-launched-from-history] [--activity-multiple-task] [--activity-no-animation] [--activity-no-history] [--activity-no-user-action] [--activity-previous-is-top] [--activity-reorder-to-front] [--activity-reset-task-if-needed] [--activity-single-top] [--receiver-registered-only] [--receiver-replace-pending] [ ]
reference: Run Android Application from Command Line
2010年10月27日 星期三
[Android] Build the linux kernel and Android source for the emulator
Build linux kerenl(Eclair):
1.check current kernel version of emulator
Build Android source:
1.building and compiling Android source
Start emulator:
reference:
* Howto BUILD the LINUX KERNEL for the ANDROID EMULATOR (Eclair version)
* Building Android kernel images
* 編譯android原始碼到模擬器上執行
1.check current kernel version of emulator
$ adb shell2.download kernel source
# cat /proc/version
Linux version 2.6.29-00261-g0097074-dirty (digit@digit.mtv.corp.google.com) (gcc version 4.4.0 (GCC) ) #20 Wed Mar 31 09:54:02 PDT 2010
$ git clone git://android.git.kernel.org/kernel/common3.check branch
$ git branchif it shows * android-2.6.27, list all remote available branches
* android-2.6.27
$ git branch -r4.switch branch
origin/HEAD -> origin/android-2.6.27
origin/android-2.6.25
origin/android-2.6.27
origin/android-2.6.29
origin/android-2.6.32
origin/android-2.6.35
origin/android-2.6.36
origin/android-goldfish-2.6.27
origin/android-goldfish-2.6.29
$ git checkout --track -b android-goldfish-2.6.29 origin/android-goldfish-2.6.295.check branch again
$ git branch6.obtain kernel configuration
android-2.6.27
* android-goldfish-2.6.29
$ cd /path/to/kernel/common7.building and compiling the kernel
$ adb pull /proc/config.gz .
$ gunzip config.gz
$ cp config .config
$ ARCH=arm CROSS_COMPILE=/path/to/android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- make8.successful message
Kernel: arch/arm/boot/Image is ready
Kernel: arch/arm/boot/zImage is ready
Build Android source:
1.building and compiling Android source
$ PATH=/path/to/android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin2.successful message
$ cd /path/to/android/
$ make
Install system fs image: out/target/product/generic/system.img
Target ram disk: out/target/product/generic/ramdisk.img
Target userdata fs image: out/target/product/generic/userdata.img
Start emulator:
$ emulator -kernel /path/to/kernel/common/arch/arm/boot/zImage -show-kernel -verbose -image /path/to/android/out/target/product/generic/system.img -data /path/to/android/out/target/product/generic/userdata.img -ramdisk /path/to/android/out/target/product/generic/ramdisk.img
reference:
* Howto BUILD the LINUX KERNEL for the ANDROID EMULATOR (Eclair version)
* Building Android kernel images
* 編譯android原始碼到模擬器上執行
[Tips] Some problems you may meet when compiling Android
OS: Ubuntu 10.04
編譯Donut:
檢查gcc的版本
若是為4.4.0以上的版本, 則因為該版本在編譯時的語法要求較高, 導致編譯失敗, 解決方法是降gcc的版本
也可以透過update-alternatives工具做切換(symbolic links)
安裝各版本的gcc
使用update-alternatives
建立symbolic links(update-alternatives --install <link> <name> <path> <priority>)
切換gcc版本
顯示結果
編譯Eclair/Froyo:
編輯/etc/security/limits.conf, 註解掉
reference: Android4SAM FAQ
編譯Donut:
development/emulator/qtools/trace_reader.cpp: In function 'char* ExtractDexPathFromMmap(const char*)':
development/emulator/qtools/trace_reader.cpp:1012: error: invalid conversion from 'const char*' to 'char*'
development/emulator/qtools/trace_reader.cpp:1015: error: invalid conversion from 'const char*' to 'char*'
make: *** [out/host/linux-x86/obj/EXECUTABLES/bb2sym_intermediates/trace_reader.o] error 1
檢查gcc的版本
$ ls -al /usr/bin/gcc
$ gcc --version
若是為4.4.0以上的版本, 則因為該版本在編譯時的語法要求較高, 導致編譯失敗, 解決方法是降gcc的版本
$ sudo apt-get install gcc-4.3
$ sudo apt-get install g++-4.3
$ sudo ln -f /usr/bin/gcc-4.3 /usr/bin/gcc
$ sudo ln -f /usr/bin/g++-4.3 /usr/bin/g++
也可以透過update-alternatives工具做切換(symbolic links)
安裝各版本的gcc
$ sudo apt-get install gcc-4.1 gcc-4.3 gcc-4.4
使用update-alternatives
Usage: update-alternatives [<option> ...] <command> Commands: --install <link> <name> <path> <priority> <link> is the symlink pointing to /etc/alternatives/<name>. (e.g. /usr/bin/pager) <name> is the master name for this link group. (e.g. pager) <path> is the location of one of the alternative target files. (e.g. /usr/bin/less) <priority> is an integer; options with higher numbers have higher priority in automatic mode.
建立symbolic links(update-alternatives --install <link> <name> <path> <priority>)
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.1 1
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 2
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 3
切換gcc版本
$ sudo update-alternatives --config gcc
顯示結果
Selection Path Priority Status ------------------------------------------------------------ 0 /usr/bin/gcc-4.1 1 auto mode 1 /usr/bin/gcc-4.1 1 manual mode * 2 /usr/bin/gcc-4.3 2 manual mode 3 /usr/bin/gcc-4.4 3 manual mode Press enter to keep the current choice[*], or type selection number:reference: [Android開發]Android開發環境建立-gcc的問題
編譯Eclair/Froyo:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/tools/StandardJavaFileManager
at java.lang.ClassLoader.defineClass2(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:719)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:160)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:254)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at com.sun.tools.javac.main.Main.compile(Main.java:269)
at com.sun.tools.javac.Main.compile(Main.java:87)
at util.build.JavacBuildStep.build(JavacBuildStep.java:69)
at util.build.BuildDalvikSuite.handleTests(BuildDalvikSuite.java:498)
at util.build.BuildDalvikSuite.compose(BuildDalvikSuite.java:170)
at util.build.BuildDalvikSuite.main(BuildDalvikSuite.java:136)
make: *** [out/host/linux-x86/obj/EXECUTABLES/vm-tests_intermediates/tests] Error 1
編輯/etc/security/limits.conf, 註解掉
#* hard nofile 4096新增
* soft nofile 8192
* hard nofile 8192
target Java: Browser (out/target/common/obj/APPS/Browser_intermediates/classes)之前提到在Ubuntu使用sun-java-sdk, 若是在java6的環境編譯時就會出現以上問題, 原因大概是@override annotation的關係, 可是JDK 1.6當然有支援annotation, 這部份未來再補充
packages/apps/Browser/src/com/android/browser/DownloadTouchIcon.java:81: cannot find symbol
symbol : method getPreferredHttpHost(android.content.Context,java.lang.String)
location: class android.net.Proxy
HttpHost httpHost = Proxy.getPreferredHttpHost(mContext, url);
^
packages/apps/Browser/src/com/android/browser/FetchUrlMimeType.java:73: cannot find symbol
symbol : method getPreferredHttpHost(com.android.browser.BrowserActivity,java.lang.String)
location: class android.net.Proxy
HttpHost httpHost = Proxy.getPreferredHttpHost(mActivity, uri);
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors
make: *** [out/target/common/obj/APPS/Browser_intermediates/classes-full-debug.jar] Error 41
reference: Android4SAM FAQ
[Tips] 常用到的Android SDK Commands
create sdcard
create emulator
list emulator
start emulator
install apk via Internet
tcpdump
$ mksdcard [SDCARD_SIZE]M [SDCARD_NAME]
create emulator
$ android create avd --target [TARGET_VER] --name [TARGET_NAME] --sdcard [SDCARD_NAME]
list emulator
$ android list avd
start emulator
$ emulator -avd [TARGET_NAME] -sdcard /path/to/sdcard
install apk via Internet
$ adb export ADBHOST=[MY_ANDROID_IP]
$ /path/to/sdk/tools/adb kill-server
$ adb install [MY_APP.apk]
tcpdump
$ adb shell tcpdump -i any -p -s 0 -w /sdcard/capture.pcap
"-i any": listen on any network interface
"-p": disable promiscuous mode (doesn't work anyway)
"-s 0": capture the entire packet
"-w": write packets to a file (rather than printing to stdout)
2010年10月22日 星期五
[Tips] 在Ubuntu使用sun-java-sdk
/** update @ 2011-09-22 **/
由於jaunty archive已經找不到sun的JDK package,所以現在只能去oracle官網下載:
* jdk-1.5
* jdk-6
一開始在寫Android的應用程式時,都是使用openjdk做為java sdk,
可是總是有說不出的怪,偶爾也會踢到不知名的鐵板,
因此換掉openjdk就是必要的動作啦...
新增repository
更新repository內容
安裝sun-java-sdk
更新jre/sdk
那到底是要選擇哪個版本呢? It depends...
比如說在編譯Android source code時,如果使用jdk-1.6的版本,就會遇到以下錯誤訊息,改成jdk-1.5就沒問題了
但是如果要使用Android的Draw 9-patch工具時,如果使用jdk-1.5的版本,就會遇到以下錯誤訊息,改成jdk-1.6就沒問題了
reference:
* Oracle Sun JDK vs OpenJDK
* How to install Sun Java 1.5 on Ubuntu 10.04
* JAVA音樂播放器YOYOPlayer1.1發佈
由於jaunty archive已經找不到sun的JDK package,所以現在只能去oracle官網下載:
* jdk-1.5
* jdk-6
一開始在寫Android的應用程式時,都是使用openjdk做為java sdk,
可是總是有說不出的怪,偶爾也會踢到不知名的鐵板,
因此換掉openjdk就是必要的動作啦...
新增repository
// jdk-1.5
$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ jaunty multiverse"
$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ jaunty-updates multiverse"
// jdk-1.6
$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
更新repository內容
$ sudo apt-get update
安裝sun-java-sdk
// jdk-1.5
$ sudo apt-get install sun-java5-jdk sun-java5-plugin
// jdk-1.6
$ sudo apt-get install sun-java6-jdk sun-java6-plugin
更新jre/sdk
// 手動更改
$ update-alternatives --config java
$ update-alternatives --config javac
// 指定更改為jdk-1.6
$ sudo update-java-alternatives -s java-6-sun
那到底是要選擇哪個版本呢? It depends...
比如說在編譯Android source code時,如果使用jdk-1.6的版本,就會遇到以下錯誤訊息,改成jdk-1.5就沒問題了
Checking build tools versions...
********************************************************
You are attempting to build with the incorrect version
of java.
Your version is: java version "1.6.0_22".
The correct version is: 1.5.
Please follow the machine setup instructions at
http://source.android.com/download
********************************************************
build/core/main.mk:117: *** stop. Stop.
但是如果要使用Android的Draw 9-patch工具時,如果使用jdk-1.5的版本,就會遇到以下錯誤訊息,改成jdk-1.6就沒問題了
/usr/share/themes/Ambiance/gtk-2.0/gtkrc:71: Failed to parse property value " GTK_SHADOW_NONE " for `GtkToolbar::shadow-type'
/usr/share/themes/Ambiance/gtk-2.0/gtkrc:72: Failed to parse property value " GTK_SHADOW_NONE " for `GtkMenuBar::shadow-type'
/usr/share/themes/Ambiance/gtk-2.0/gtkrc:75: error: lexical error or unexpected token, expected valid token
reference:
* Oracle Sun JDK vs OpenJDK
* How to install Sun Java 1.5 on Ubuntu 10.04
* JAVA音樂播放器YOYOPlayer1.1發佈
2010年10月20日 星期三
[Tips] Control Your Android Device Remotely Using Mouse and Keyboard
Download: androidscreencast
Launch: $ javaws <jnlp file>
Limitations: slow refresh rate (about 4-5 fps)
Google Code Project here
Launch: $ javaws <jnlp file>
Limitations: slow refresh rate (about 4-5 fps)
Google Code Project here
2010年10月8日 星期五
[Android] 開機自動啟動的service
程式架構
直接看扣,
HelloReceiver.java
DoService.java
AndroidManifest.xml
reference:
* Running code on phone boot
* Starting an Android service after boot
|-- AndroidManifext.xml // --> 設定receiver, service, uses-permission `-- src |-- DoService.java // --> 實際執行的service `-- HelloReceiver.java // --> 接受啟動訊息, 再啟動DoService
直接看扣,
HelloReceiver.java
package hello.receiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class HelloReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { context.startService(new Intent(context, DoService.class)); } }
DoService.java
package hello.receiver; import android.app.Service; import android.content.Intent; import android.os.Handler; import android.os.IBinder; public class DoService extends Service { private Handler handler = new Handler(); private int delay_interval = 1000 * 60; // do every 60 seconds @Override public void onStart(Intent intent, int startId) { handler.postDelayed(doUpdate, delay_interval); super.onStart(intent, startId); } public Runnable doUpdate = new Runnable() { public void run() { handler.postDelayed(this, delay_interval); } }; @Override public IBinder onBind(Intent arg0) { return null; } }
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="hello.receiver" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".HelloReceiver" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name="HelloReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.HOME" /> </intent-filter> </receiver> <service android:name=".myThread"> <intent-filter> <action android:name="hello.receiver.DoService" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </service> </application> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission> </manifest>
reference:
* Running code on phone boot
* Starting an Android service after boot
2010年9月30日 星期四
[轉貼] [Android] JAR Library: Export and Import
原文標題: [Android] JAR Library: Export and Import
原文作者: web_surf@163.com
發表日期: 2010-06-18 09:42
原文來源: https://bbs.et8.net/bbs/showthread.php?t=616987
1.Export Library
2.Import Library
簡單的作法是靠Eclipse的Project->Export, 僅選取src的部份, 匯出即可
Import還是靠Eclipse的Project->Properties->Java Build Path->Libraries->Add External JARs即可
原文作者: web_surf@163.com
發表日期: 2010-06-18 09:42
原文來源: https://bbs.et8.net/bbs/showthread.php?t=616987
1.Export Library
* Prepare source code
- Create an Android project
- Create source code, and fix all bug
- Remove res/*
- Remove unused source files
- Edit AndroidManifest.xml to remove the statements that referes to resource, such as android:icon="@drwable/icon", android:label="@string/app_name"* Export library
- On Package Explorer Panel of Eclipse, right-click the project, and select Export
- Select Jave -> JAR file, then press "Next". At this time a dialog pops up.
- On the right panel of "Select the resources to export:" group, unselect all items (such as .classpath, .project, AndroidManifest.xlm, default.properties), then press "Next"
Press "Next"
Press "Finish"
Then the library is created.
(Reference: Eclipse export jar files http://hi.baidu.com/etrigger/blog/item/e1fed134468b2fb2d0a2d3ad.html)
* xxx
2.Import Library
You can use a third party JAR in your application by adding it to your Eclipse project as follows:
- In the Package Explorer panel, right-click on your project and select Properties.
- Select Java Build Path, then the tab Libraries.
- Press the Add External JARs... button and select the JAR file
Alternatively, if you want to include third party JARs with your package, create a new directory for them within your project and select Add Library... instead.
It is not necessary to put external JARs in the assets folder.
(Reference: http://code.google.com/intl/zh-CN/android/kb/commontasks.html)
簡單的作法是靠Eclipse的Project->Export, 僅選取src的部份, 匯出即可
Import還是靠Eclipse的Project->Properties->Java Build Path->Libraries->Add External JARs即可
訂閱:
文章 (Atom)