Wednesday, July 23, 2014

在Linux下载Android源代码

1. Change to root

$ sudo su


2. Installing the JDK:

$ sudo apt-get update (with proxy: sudo env http_proxy=
http://10.1.3.1:8080 apt-get update)

$ sudo apt-get install openjdk-7-jdk

3. curl工具的安装:
sudo apt-get install curl

4. git工具的安装
sudo apt-get install git-core


5. make new dir
mkdir Android
cd Android

6. repo工具的安装
chmod a+x repo
apt-get install phablet-tools

7. 下载源代码

$ repo init -u https://android.googlesource.com/platform/manifest
(proxy: 如果要设置代理,先运行git config --global http.proxy localhost:8080,再运行repo init)
出现错误是补充如下信息:
git config --global user.email "cenjiajie@gmail.com"
git config --global user.name "gary"

最后运行
$ repo sync

运行了一晚后,结果是(这时占用了17G)




8. Build
$ sudo apt-get install git gnupg flex bison gperf build-essential \
  zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
  libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
  libgl1-mesa-dev g++-multilib mingw32 tofrodos \
  python-markdown libxml2-utils xsltproc zlib1g-dev:i386
$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

$ . build/envsetup.sh

指定输出路径,这样可以界面交互
export OUT_DIR_COMMON_BASE=/home/gary/Android

root@gary-virtual-machine:~/bin# lunch

You're building on Linux

Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_arm64-eng
     3. aosp_mips-eng
     4. aosp_mips64-eng
     5. aosp_x86-eng
     6. aosp_x86_64-eng
     7. vbox_x86-eng
     8. aosp_manta-userdebug
     9. mini_mips-userdebug
     10. mini_armv7a_neon-userdebug
     11. mini_x86-userdebug
     12. aosp_tilapia-userdebug
     13. aosp_deb-userdebug
     14. aosp_flo-userdebug
     15. aosp_grouper-userdebug
     16. aosp_mako-userdebug
     17. aosp_hammerhead-userdebug


<select 5>

make -j4
--failed
make




http://www.linuxidc.com/Linux/2011-02/32269.htm


官方参考:
https://source.android.com/source/initializing.html
百度经验:

http://jingyan.baidu.com/article/03b2f78c44e2a55ea337ae5b.html

Thursday, July 17, 2014

在windows利用VMware安装Ubuntu

1. 在http://www.ubuntu.com/   下载Ubuntu,我选的是64位系统
2. 下载并安装VMware Workstation 8.0

安装过程注意在bios设置enable visualization technology, 如果要用于下载Android源代码,内存至少2G,硬盘至少100G

百度经验
http://jingyan.baidu.com/article/14bd256e0ca52ebb6d26129c.html
其中,有时可能光盘为空,这时需要把光盘eject再重新按install VMware tools

安装完Ubuntu下一个问题是屏幕不够大,这里需要安装VMware tools来解决,具体见:

百度经验(看前6步即可):
http://jingyan.baidu.com/article/3065b3b6e8dedabecff8a435.html

然后按Ctrl+Alt+T出现terminal的窗口,输入:
cd Desktop
cd vmware-tools-disturib 

sudo ./vmware-install.pl  

安装一直回车即用默认值,一直到安装完毕,然后重启虚拟器
这时候可以见到VMware里面View->Fit Guest now选项可以选了,按一下就全屏了!

















Sunday, June 8, 2014

改变affinity - CPU利用数

由于Android emulator存在bug - 只能单cpu运行,所以我们必须在emulator启动后,改变其affinity,使其可以多CPU运行

PowShell "Get-Process"

PowerShell "Get-Process calc | Select-Object ProcessorAffinity"
PowerShell "$Process = Get-Process calc; $Process.ProcessorAffinity=255"


PowerShell "Get-Process | where-Object {$_.mainWindowTitle} | format-table id,name,mainwindowtitle -AutoSize"

PowerShell "Get-Process | where-Object {$_.mainWindowTitle -like 'calculator'} | format-table id,name,mainwindowtitle -AutoSize"

Id Name MainWindowTitle
-- ---- ---------------
40312 calc Calculator


PowerShell "$Process = Get-Process | where-Object {$_.mainWindowTitle -like 'calculator'}; $Process.ProcessorAffinity=255"



PowerShell "$Process = Get-Process | where-Object {$_.mainWindowTitle -like '5554:test'}; $Process.ProcessorAffinity=255"


Wednesday, May 28, 2014

Android emulator加速和代理

软件加速:
avd设置中,选use host gpu

硬件加速:
1. 在bios设置, enable visualization technology.
2. cmd输入sc query intelhaxm见到尽管硬件设置了,但软件未安装
3. SDK manager下载intel accelarate








4. Go to android SDK folder,  sdk\extras\intel\Hardware_Accelerated_Execution_Manager\intelhaxm.exe, 安装时候,按需要提高内存上限(默认2G)
5. 在Android SDK manager安装 google APIs (x86 system image) and google APIs ( ARM system image) and Intel x86 Emulator Accelerated(HAXM installer)
这时候重复步骤2可见intelhaxm服务开始了
6. Avd设置中,target选google APIs(x86 system image), skin WXga800-7in
或者cmd: emulator -avd nexus5 -gpu on

代理proxy:
在安装apk到虚拟器emulator一文提到用cmd设置proxy,但笔者用后觉得emulator容易暂停或死机,这里用emulator中设置方法达到:
1. 打开emualotor
2. Settings->more->mobile networks->check data enabled option and click 
access point name->us t-mobile
设置Proxy, port, 置空username password
右上角Save

如果要创建文件:
1. 在创建avd时候设置sd card

Reference:
Android using hardware acceleration 
http://developer.android.com/tools/devices/emulator.html#acceleration

Friday, May 9, 2014

UiAutomator简介(4) - 输入中文

这一节主要讲怎么settext中输入中文,方法主要是用一个外部包

步骤主要如下:
1. 安装Utf7ImeHelper.apk
2. 在你的代码中,加入Utf7ImeHelper.java,并且调用setText(Utf7ImeHelper.e(“我们women”))

当你运行UiAutomator时候,输入文字,不会出现键盘



详细可以参考:
http://testerhome.com/topics/678
http://testerhome.com/topics/408

Wednesday, April 30, 2014

Java之OCR

Java的OCR有一个简单的lib是ocr4j.jar,他可以识别背景不复杂的文字

              OCR ocr = null;
              try {
                     ocr = new OCR();
              } catch (IOException e2) {
                     // TODO Auto-generated catch block
                     e2.printStackTrace();
              }
              File img = new File("C:\\Users\\KK\\Documents\\Coding\\Java\\IMG_2915.PNG");
              try {
                     String text = ocr.recognise(ImageIO.read(img));
                     System.out.print(text);
              } catch (IOException e1) {
                     // TODO Auto-generated catch block
                     e1.printStackTrace();

              }

图片如下:


References:
[1] http://ocr4j.sourceforge.net/









Saturday, April 26, 2014

KB: Java之反射

import java.lang.reflect.*;

1.得到类名:Class c = Class.forName(this.getClass().getName().toString()); this为instance,如果这句在基类,类,getClass会得到给子类。class name是包括包名的,比如com.vtasters.entity.Car Car是类名
2. 得到某类(this)的某属性:c.getField("location").get(this),如果该属性是static,就如下c.getField("location").get(null)
3. 设置某类(this)的某属性:c.getField("location").set(this, "Jersey city");
4. 获得某类某属性的类型:
Field fields[] = c.getDeclaredFields();
for(Field f : fields)
{
            f.getType()
5. 调用方法:
    Class cls=null;
    cls=Class.forName("com.vtasters.Dish");
    Object obj=cls.newInstance();
    Method method=cls.getMethod("Test",null);
    method.invoke(obj);
    这里调用一个没有参数叫Test的方法

     Class cls=null;
  cls = Class.forName("com.framework.Action");

  Object obj = cls.newInstance();

  Class[] cArg = new Class[2];
  cArg[0] = int.class;
  cArg[1] = String.class;
  Method method2 = cls.getMethod("bbb", cArg);
  Object returnType = method2.getReturnType();
  Object value = method2.invoke(obj,5,"6");
  System.out.println(returnType.toString()+":"+value.toString());

    这里调用一个带参数和返回值叫bbb的方法,定义如下
    int bbb(int a, String b){}

    注意,有时一些内部类带的属性或方法,不能在被调用的方法(e.g. bbb)中使用,要作为参数输入,否则会出现Reflection异常

如果参数个数是动态,就这样写:
       String[] mainArgs = new String[5];
      method.invoke(null, (Object)mainArgs);
getDeclaredMethod可以得到protected的方法,但getMethod只能得到公共方法

6. 返回值
Object value = method.invoke(this, x);
                d = (Double) value;

7. 调用构造函数
            cls = Class.forName("com.itg.generic.Events");
            Class[] constructorArg = new Class[1];
            constructorArg[0] = Operator.class;
            Object obj = cls.getDeclaredConstructor(constructorArg).newInstance(this);

8. 判断一个数据是否实例
    Num param instanceof Double

a=="mystr"不对,要用a.equals("mystr")