您的位置:首页 > 移动开发

在Android5.1系统源码中加入测试APP应用程序

2017-04-22 17:34 316 查看
环境:
源码编译环境: Ubuntu14.04 x86-x64系统 -- Java1.7
硬件测试环境: Nexus5 手机
源码分支: repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-5.1.1_r4

APP(package="shy.luo.hello")的主函数代码如下:
----------------------------------------------------------------------------------------------
public class HelloAndroid extends Activity {
    private final static String LOG_TAG = "shy.luo.hello.HelloAndroid";

    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            // print debug statck info;
            try{
              throw new Exception("Call stack Trace");
            }catch(Exception e){
              Log.i(LOG_TAG,"print_stack", e);
            }

            Log.i(LOG_TAG, "HelloAndroid Activity Created.");
        }
}
----------------------------------------------------------------------------------------------

编译APP:
android_5.1_nexus5/android_5.1_lmy48m$ java -version
java version "1.7.0_121"
OpenJDK Runtime Environment (IcedTea 2.6.8) (7u121-2.6.8-1ubuntu0.14.04.3)
OpenJDK 64-Bit Server VM (build 24.121-b00, mixed mode)
android_5.1_nexus5/android_5.1_lmy48m$ source build/envsetup.sh
android_5.1_nexus5/android_5.1_lmy48m$ lunch ( Nexus5 设备选择: 7. aosp_hammerhead-userdebug )
android_5.1_nexus5/android_5.1_lmy48m$ mmm packages/experimental/HelloAndroid
Install: out/target/product/hammerhead/system/app/HelloAndroid/HelloAndroid.apk
make: Leaving directory `/home/yanping/code/android/system/android_5.1_nexus5/android_5.1_lmy48m'

#### make completed successfully (8 seconds) ####

重新打包Android系统镜像文件:
android_5.1_nexus5/android_5.1_lmy48m$ make snod
(执行make snod命令,即可重新打包Android系统镜像文件system.img)

重启Nexus5进入BootLoader模式:
android_5.1_nexus5/android_5.1_lmy48m$ adb reboot bootloader

刷机测试打印:
android_5.1_nexus5/android_5.1_lmy48m$ fastboot flashall -w
待刷机完整,系统自动重启进入系统,点击启动HelloWorld应用,然后我们adb进入系统,使用logcat查看日志:
android_5.1_nexus5/android_5.1_lmy48m$ adb shell
shell@hammerhead:/ $ logcat | grep "shy.luo.hello.HelloAndroid"
I/shy.luo.hello.HelloAndroid( 2854): print_stack
I/shy.luo.hello.HelloAndroid( 2854): java.lang.Exception: Call stack Trace
I/shy.luo.hello.HelloAndroid( 2854):    at shy.luo.hello.HelloAndroid.onCreate(HelloAndroid.java:17)
I/shy.luo.hello.HelloAndroid( 2854):    at android.app.Activity.performCreate(Activity.java:5990)
I/shy.luo.hello.HelloAndroid( 2854):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
I/shy.luo.hello.HelloAndroid( 2854):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
I/shy.luo.hello.HelloAndroid( 2854):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
I/shy.luo.hello.HelloAndroid( 2854):    at android.app.ActivityThread.access$800(ActivityThread.java:151)
I/shy.luo.hello.HelloAndroid( 2854):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
I/shy.luo.hello.HelloAndroid( 2854):    at android.os.Handler.dispatchMessage(Handler.java:102)
I/shy.luo.hello.HelloAndroid( 2854):    at android.os.Looper.loop(Looper.java:135)
I/shy.luo.hello.HelloAndroid( 2854):    at android.app.ActivityThread.main(ActivityThread.java:5254)
I/shy.luo.hello.HelloAndroid( 2854):    at java.lang.reflect.Method.invoke(Native Method)
I/shy.luo.hello.HelloAndroid( 2854):    at java.lang.reflect.Method.invoke(Method.java:372)
I/shy.luo.hello.HelloAndroid( 2854):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
I/shy.luo.hello.HelloAndroid( 2854):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
I/shy.luo.hello.HelloAndroid( 2854): HelloAndroid Activity Created.
V/WindowManager(  726): Adding window Window{49e1af7 u0 shy.luo.hello/shy.luo.hello.HelloAndroid} at 2 of 8 (before Window{26002aa0 u0 Starting shy.luo.hello})


这样,我们就可以以这种方式在Android源码中加入我们自己写的APP了,另外,Java层的调试打印堆栈也测试通过;
获取Java函数调用栈;
----------------------------------------------
try{
throw new Exception("Call stack Trace");
}catch(Exception e){
Log.i("shyluo@gamil.com","xxx", e);
}

----------------------------------------------

参考链接:
http://0xcc0xcd.com/p/books/978-7-121-18108-5/c162.php
http://0xcc0xcd.com/p/videos/debug-aosp.php
HelloAndroid APP源码下载: http://download.csdn.net/detail/ypist/9822361
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ubuntu nexus android 源码
相关文章推荐