博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android hal学习——测试整个流程【转】
阅读量:2193 次
发布时间:2019-05-02

本文共 16751 字,大约阅读时间需要 55 分钟。

from:http://blog.csdn.net/brightming/article/details/49884651

一、参考 
需要参考在源码中如何编译apk。 
 
 
在packages/apps/目录下有不少app,可以参考。

二、 
1、写app 
1)在 studio中写好空的工程 
2)编辑strings.xml

example1
Hello world!
Settings
value
hint
read
write
clear
1
2
3
4
5
6
7
8
9
10
11
1
2
3
4
5
6
7
8
9
10
11

3)编辑activity_main.xml,结果为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

4)编辑activity类,结果为:

package com.example.gumh.example1;import android.app.Activity;import android.os.Bundle;import android.os.IExampleService;import android.os.RemoteException;import android.os.ServiceManager;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import com.example.gumh.example1.R;public class MainActivity extends Activity implements OnClickListener {
private final static String LOG_TAG = "com.example.gumh.example1.MainActivity"; private IExampleService exampleService = null; private EditText valueText = null; private Button readButton = null; private Button writeButton = null; private Button clearButton = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); exampleService = IExampleService.Stub.asInterface( ServiceManager.getService("example")); valueText = (EditText)findViewById(R.id.edit_value); readButton = (Button)findViewById(R.id.button_read); writeButton = (Button)findViewById(R.id.button_write); clearButton = (Button)findViewById(R.id.button_clear); readButton.setOnClickListener(this); writeButton.setOnClickListener(this); clearButton.setOnClickListener(this); Log.i(LOG_TAG, "Example Activity Created"); } @Override public void onClick(View v) { if(v.equals(readButton)) { try { int val = exampleService.getVal(); String text = String.valueOf(val); valueText.setText(text); } catch (RemoteException e) { Log.e(LOG_TAG, "Remote Exception while reading value from example service."); } } else if(v.equals(writeButton)) { try { String text = valueText.getText().toString(); int val = Integer.parseInt(text); exampleService.setVal(val); } catch (RemoteException e) { Log.e(LOG_TAG, "Remote Exception while writing value to example service."); } } else if(v.equals(clearButton)) { String text = ""; valueText.setText(text); } }}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

5)在android源码下的app下新增example1文件夹: 
packages/apps/example1

6)新增Android.mk文件:

[zzz@localhost example1]$ cat Android.mk LOCAL_PATH:=$(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE_TAGS:=optionalLOCAL_SRC_FILES:=$(call all-java-files-under,src)LOCAL_PACKAGE_NAME:=example1LOCAL_CERTIFICATE:=platforminclude $(BUILD_PACKAGE) 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

7)复制工程部分文件到这里(因为有些gradle的东西和结构不需要) 
结果为:

[zzz@localhost example1]$ pwd/home/zzz/opensource/android-src/packages/apps/example1[zzz@localhost example1]$ ll-rw-rw-r--.  1 zzz zzz  691 Nov 17 11:30 AndroidManifest.xml-rw-rw-r--.  1 zzz zzz  217 Nov 17 11:41 Android.mkdrwxrwxr-x. 11 zzz zzz 4096 Nov 17 11:30 resdrwxrwxr-x.  3 zzz zzz 4096 Nov 17 11:38 src 
1
2
3
4
5
6
7
1
2
3
4
5
6
7
[zzz@localhost example1]$ ll src/com/example/zzz/example1/MainActivity.java -rw-rw-r--. 1 zzz zzz 2434 Nov 17 12:03 src/com/example/zzz/example1/MainActivity.java 
1
2
1
2

2、编译app

[zzz@localhost android-src]$  mmm packages/apps/example1/ ============================================PLATFORM_VERSION_CODENAME=RELPLATFORM_VERSION=6.0TARGET_PRODUCT=aosp_armTARGET_BUILD_VARIANT=engTARGET_BUILD_TYPE=releaseTARGET_BUILD_APPS=TARGET_ARCH=armTARGET_ARCH_VARIANT=armv7-aTARGET_CPU_VARIANT=genericTARGET_2ND_ARCH=TARGET_2ND_ARCH_VARIANT=TARGET_2ND_CPU_VARIANT=HOST_ARCH=x86_64HOST_OS=linuxHOST_OS_EXTRA=Linux-3.10.0-229.14.1.el7.x86_64-x86_64-with-centos-7.1.1503-CoreHOST_CROSS_OS=windowsHOST_BUILD_TYPE=releaseBUILD_ID=MASTEROUT_DIR=out============================================Unknown option: -Cusage: git [--version] [--help] [-c name=value]           [--exec-path[=
]] [--html-path] [--man-path] [--info-path] [-p|--paginate|--no-pager] [--no-replace-objects] [--bare] [--git-dir=
] [--work-tree=
] [--namespace=
]
[
]make: Entering directory `/home/gumh/opensource/android-src'Running kati to generate build-aosp_arm-mmm-packages_apps_example1_Android.mk.ninja...No need to regenerate ninja fileStarting build with ninjaninja: Entering directory `.'[ 83% 5/6] build out/target/product/ge...le1_intermediates/oat/arm/package.odexdex2oatd W 19919 19919 art/runtime/arch/arm/instruction_set_features_arm.cc:96] Unknown instruction set features for ARM CPU variant (generic) using conservative defaultsdex2oatd I 19919 19919 art/dex2oat/dex2oat.cc:1944] out/host/linux-x86/bin/dex2oatd --runtime-arg -Xms64m --runtime-arg -Xmx512m --boot-image=out/target/product/generic/dex_bootjars/system/framework/boot.art --dex-file=out/target/product/generic/obj/APPS/example1_intermediates/oat/arm/package.odex.input --dex-location=/system/app/example1/example1.apk --oat-file=out/target/product/generic/obj/APPS/example1_intermediates/oat/arm/package.odex --android-root=out/target/product/generic/system --instruction-set=arm --instruction-set-variant=generic --instruction-set-features=default --include-patch-information --runtime-arg -Xnorelocate --no-generate-debug-info --abort-on-hard-verifier-errordex2oatd I 19919 19919 art/runtime/gc/space/image_space.cc:692] Dumping image sectionsdex2oatd I 19919 19919 art/runtime/gc/space/image_space.cc:696] SectionObjects start=0x70000000 size=3015800 range=0-3015800dex2oatd I 19919 19919 art/runtime/gc/space/image_space.cc:696] SectionArtFields start=0x702e0478 size=544436 range=3015800-3560236dex2oatd I 19919 19919 art/runtime/gc/space/image_space.cc:696] SectionArtMethods start=0x7036532c size=1993956 range=3560236-5554192dex2oatd I 19919 19919 art/runtime/gc/space/image_space.cc:696] SectionDexCacheArrays start=0x7054c010 size=2139552 range=5554192-7693744dex2oatd I 19919 19919 art/runtime/gc/space/image_space.cc:696] SectionInternedStrings start=0x707565b0 size=114840 range=7693744-7808584dex2oatd I 19919 19919 art/runtime/gc/space/image_space.cc:696] SectionImageBitmap start=0x70773000 size=49152 range=7811072-7860224dex2oatd I 19919 19919 art/dex2oat/dex2oat.cc:1742] dex2oat took 1.030s (threads: 4) arena alloc=137KB java alloc=56KB native alloc=267KB free=436KBdex2oatd I 19919 19919 art/dex2oat/dex2oat.cc:1742] Code dedupe: 0 collisions, 0 max hash collisions, 0/3 probe distance, 3783 ns hash timedex2oatd I 19919 19919 art/dex2oat/dex2oat.cc:1742] Mapping table dedupe: 0 collisions, 0 max hash collisions, 0/0 probe distance, 0 ns hash timedex2oatd I 19919 19919 art/dex2oat/dex2oat.cc:1742] Vmap table dedupe: 0 collisions, 0 max hash collisions, 0/3 probe distance, 847 ns hash timedex2oatd I 19919 19919 art/dex2oat/dex2oat.cc:1742] GC map dedupe: 0 collisions, 0 max hash collisions, 0/0 probe distance, 0 ns hash timedex2oatd I 19919 19919 art/dex2oat/dex2oat.cc:1742] CFI info dedupe: 0 collisions, 0 max hash collisions, 0/0 probe distance, 0 ns hash timedex2oatd W 19919 19919 art/runtime/runtime.cc:233] Current thread not detached in Runtime shutdown[100% 6/6] Install: out/target/product...tem/app/example1/oat/arm/example1.odexmake: Leaving directory `/home/zzz/opensource/android-src'#### make completed successfully (8 seconds) ####[zzz@localhost android-src]$ ll out/target/product/generic/system/app/example1/total 32-rw-rw-r--. 1 zzz zzz 24758 Nov 17 12:03 example1.apkdrwxrwxr-x. 3 zzz zzz 4096 Nov 17 12:03 oat[zzz@localhost android-src]$
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

可以看到,在输出目录已经有example1.apk了。

3、运行虚拟机 
实际上,我在out/target/product/generic/目录下用指令:

emulator -sysdir ./ -system system.img -data userdata.img -kernel ~/opensource/android/goldfish/arch/arm/boot/zImage 
1
1

虚拟机启动后,一直都是黑屏。 
而用:

emulator -data userdata.img  
1
1

确很快可以进入系统,怀疑是我加的某些代码导致内核有问题或者system.img有问题。

于是重新去对整个系统进行编译:

[zzz@localhost android-src]$ make -j4...Note: Recompile with -Xlint:unchecked for details.[  2% 49/1736] target Java: icu4j (out...LIBRARIES/icu4j_intermediates/classes)Note: Some input files use or override a deprecated API.Note: Recompile with -Xlint:deprecation for details.Note: external/icu/icu4j/main/classes/core/src/com/ibm/icu/impl/Relation.java uses unchecked or unsafe operations.Note: Recompile with -Xlint:unchecked for details.[  5% 88/1736] Docs droiddoc: out/target/common/docs/api-stubsDroidDoc took 85 sec. to write docs to out/target/common/docs/api-stubs[  5% 90/1736] Docs droiddoc: out/target/common/docs/system-api-stubsDroidDoc took 83 sec. to write docs to out/target/common/docs/system-api-stubs[  5% 92/1736] Checking API:  checkpublicapi-currentFAILED: /bin/bash -c "(true) && ( out/host/linux-x86/bin/apicheck -JXmx1024m -J\"classpath /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/bin/../lib/tools.jar:out/host/linux-x86/framework/doclava.jar:out/host/linux-x86/framework/jsilver.jar\"  -error 2 -error 3 -error 4 -error 5 -error 6 -error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 -error 14 -error 15 -error 16 -error 17 -error 18 -error 19 -error 20 -error 21 -error 23 -error 24 -error 25 -error 26 -error 27  frameworks/base/api/current.txt  out/target/common/obj/PACKAGING/public_api.txt  frameworks/base/api/removed.txt  out/target/common/obj/PACKAGING/removed.txt || (  cat build/core/apicheck_msg_current.txt ; exit 38 ) ) && (mkdir -p out/target/common/obj/PACKAGING/) && (touch out/target/common/obj/PACKAGING/checkpublicapi-current-timestamp)"out/target/common/obj/PACKAGING/public_api.txt:23087: error 3: Added class IExampleService to package android.osout/target/common/obj/PACKAGING/public_api.txt:23092: error 3: Added class IExampleService.Stub to package android.os******************************You have tried to change the API from what has been previously approved.To make these errors go away, you have two choices:   1) You can add "@hide" javadoc comments to the methods, etc. listed in the      errors above.   2) You can update current.txt by executing the following command:         make update-api      To submit the revised current.txt to the main Android repository,      you will need approval.******************************[  5% 92/1736] Checking API:  checksystemapi-currentFAILED: /bin/bash -c "(true) && ( out/host/linux-x86/bin/apicheck -JXmx1024m -J\"classpath /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/bin/../lib/tools.jar:out/host/linux-x86/framework/doclava.jar:out/host/linux-x86/framework/jsilver.jar\"  -error 2 -error 3 -error 4 -error 5 -error 6 -error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 -error 14 -error 15 -error 16 -error 17 -error 18 -error 19 -error 20 -error 21 -error 23 -error 24 -error 25 -error 26 -error 27  frameworks/base/api/system-current.txt  out/target/common/obj/PACKAGING/system-api.txt  frameworks/base/api/system-removed.txt  out/target/common/obj/PACKAGING/system-removed.txt || (  cat build/core/apicheck_msg_current.txt ; exit 38 ) ) && (mkdir -p out/target/common/obj/PACKAGING/) && (touch out/target/common/obj/PACKAGING/checksystemapi-current-timestamp)"out/target/common/obj/PACKAGING/system-api.txt:25032: error 3: Added class IExampleService to package android.osout/target/common/obj/PACKAGING/system-api.txt:25037: error 3: Added class IExampleService.Stub to package android.os******************************You have tried to change the API from what has been previously approved.To make these errors go away, you have two choices:   1) You can add "@hide" javadoc comments to the methods, etc. listed in the      errors above.   2) You can update current.txt by executing the following command:         make update-api      To submit the revised current.txt to the main Android repository,      you will need approval.******************************[  5% 92/1736] Building with Jack: out...k_intermediates/with-local/classes.dexninja: build stopped: subcommand failed.make: *** [ninja_wrapper] Error 1[zzz@localhost android-src]$ pwd 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

看到有几个错误: 
out/target/common/obj/PACKAGING/public_api.txt:23087: error 3: Added class IExampleService to package android.os 
out/target/common/obj/PACKAGING/public_api.txt:23092: error 3: Added class IExampleService.Stub to package android.os

out/target/common/obj/PACKAGING/system-api.txt:25032: error 3: Added class IExampleService to package android.os 
out/target/common/obj/PACKAGING/system-api.txt:25037: error 3: Added class IExampleService.Stub to package android.os

用make update-api来解决,或在方法前增加 /*{@hide}/

1、增加 hide 
在那个 
frameworks/base/services/core//com/android/server/ExampleService.java 
的接口的方法setVal和getVal上增加了: 
/*{@hide} 
public void setVal(int val) {

再编译还是有问题,可能没有加对地方,先放过。

2、执行make update-api

[ 99% 281/282] Docs droiddoc: out/target/common/docs/doc-comment-checkDroidDoc took 416 sec. to write docs to out/target/common/docs/doc-comment-check[100% 282/282] Copying current.txtCopying removed.txt 
1
2
3
4
5
1
2
3
4
5

3、再次编译:

make j4...Note: Some input files use unchecked or unsafe operations.Note: Recompile with -Xlint:unchecked for details.[100% 1449/1449] host Java: ahat-test-.../ahat-test-dump_intermediates/classes)Note: art/tools/ahat/test-dump/Main.java uses unchecked or unsafe operations.Note: Recompile with -Xlint:unchecked for details 
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8

但运行虚拟机还是有问题。

你可能感兴趣的文章
Leetcode Go 《精选TOP面试题》20200628 69.x的平方根
查看>>
leetcode 130. Surrounded Regions
查看>>
【Python】详解Python多线程Selenium跨浏览器测试
查看>>
Jmeter之参数化
查看>>
Shell 和Python的区别。
查看>>
Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
查看>>
Loadrunner之https协议录制回放报错如何解决?(九)
查看>>
python中xrange和range的异同
查看>>
列表、元组、集合、字典
查看>>
【Python】easygui小甲鱼
查看>>
【Python】关于Python多线程的一篇文章转载
查看>>
【Pyton】【小甲鱼】文件
查看>>
【Pyton】【小甲鱼】永久存储:腌制一缸美味的泡菜
查看>>
【Pyton】【小甲鱼】异常处理:你不可能总是对的
查看>>
APP性能测试工具
查看>>
【Pyton】【小甲鱼】类和对象
查看>>
压力测试工具JMeter入门教程
查看>>
作为一名软件测试工程师,需要具备哪些能力
查看>>
【Pyton】【小甲鱼】类和对象:一些相关的BIF(内置函数)
查看>>
【Pyton】【小甲鱼】魔法方法
查看>>