今天的任务从早上搞到现在,才算完成,本来以为比较简单,就是出一个Demo,将实际业务的逻辑封装成so库,放在系统层,对上层不暴露任何东西,中间就一层JNI调用,原本以为很简单,但是由于自己的一个坏习惯,折腾了一天。将处理过程详细记录下来,同时吸取教训,也希望能给大家带来帮助。
JNI的封装很简单,代码就不上了,在Android7.0源码目录下添加共享库的过程,也有其他网友提到了,最重要的就是修改public.libraries.txt文件。将自己的要添加的目标库加到该文件中,如下图,可以看到该文件存在三处,system目录下两处,vendor下一处,最终编译成img文件烧录到手机上,分别是system/etc/public.libraries.txt、system/vendor/etc/public.libraries.txt、vendor/etc/public.libraries.txt,只有在这里声明过,应用才能调用,否则会因为命名空间的问题导致应用层调用失败。
自己先完成了业务逻辑的代码,然后编译成so库,push到手机上,但是发现一直停留在Android字样的动画开机界面,无法正常开机,于是开始抓log分析,正常和异常日志分别如下:
1、正常开机日志,可以看到,资料加载完成后,马上会执行startSystemServer方法启动system_server进程,相应的日志都有出现,当system_server启动成功后,界面也就快显示出来了。
Line 1694: 01-03 22:23:11.820 361 361 D Zygote : begin preload
Line 1695: 01-03 22:23:11.820 361 361 I Zygote : Installing ICU cache reference pinning...
Line 1696: 01-03 22:23:11.820 361 361 I Zygote : Preloading ICU data...
Line 1867: 01-03 22:23:12.087 361 361 I Zygote : Preloading classes...
Line 1868: 01-03 22:23:12.094 361 361 W Zygote : Class not found for preloading: [Landroid.view.Display$ColorTransform;
Line 2304: 01-03 22:23:13.874 361 361 W Zygote : Class not found for preloading: android.view.Display$ColorTransform
Line 2305: 01-03 22:23:13.875 361 361 W Zygote : Class not found for preloading: android.view.Display$ColorTransform$1
Line 2347: 01-03 22:23:14.546 361 361 I Zygote : ...preloaded 4158 classes in 2459ms.
Line 2375: 01-03 22:23:14.734 361 361 I Zygote : Preloading resources...
Line 2423: 01-03 22:23:15.081 361 361 I Zygote : ...preloaded 114 resources in 347ms.
Line 2426: 01-03 22:23:15.097 361 361 I Zygote : ...preloaded 41 resources in 17ms.
Line 2439: 01-03 22:23:15.183 361 361 I Zygote : Preloading shared libraries...
Line 2444: 01-03 22:23:15.227 361 361 I Zygote : Uninstalled ICU cache reference pinning...
Line 2445: 01-03 22:23:15.239 361 361 I Zygote : Installed AndroidKeyStoreProvider in 12ms.
Line 2446: 01-03 22:23:15.264 361 361 I Zygote : Warmed up JCA providers in 26ms.
Line 2447: 01-03 22:23:15.265 361 361 D Zygote : end preload
Line 2462: 01-03 22:23:15.448 361 361 I Zygote : System server process 2252 has been created
Line 2463: 01-03 22:23:15.455 361 361 I Zygote : Accepting command socket connections
Line 10398: 01-03 22:25:40.307 2252 2574 I Zygote : Process: zygote socket opened, supported ABIS: armeabi-v7a,armeabi
2、异常开机日志,从日志中明显可以看到,Zygote进程在加载完资料后,根据没有成功启动system_server,导致无法开机。
Line 1743: 01-03 22:16:43.383 347 347 D Zygote : begin preload
Line 1744: 01-03 22:16:43.383 347 347 I Zygote : Installing ICU cache reference pinning...
Line 1745: 01-03 22:16:43.384 347 347 I Zygote : Preloading ICU data...
Line 1914: 01-03 22:16:43.600 347 347 I Zygote : Preloading classes...
Line 1915: 01-03 22:16:43.607 347 347 W Zygote : Class not found for preloading: [Landroid.view.Display$ColorTransform;
Line 2347: 01-03 22:16:45.403 347 347 W Zygote : Class not fou