《Android插件化开发指南》勘误

一些常识:

1)全书70个代码例子中,涉及到插件的例子,请先assemble插件的项目,这会在HostApp项目中生成assets目录,并在该目录下plugin1.apk。这样,HostApp才能正常运行。

 

2)本书基于Android6.0(API level 23)的源码进行分析,本书的代码在Android7.0(API level 24)手机上测试都是能正常工作的。对于Android 7.0以上版本,有些插件化的解决方案,已经过时了,比如AMN的gDefault字段。

 

3)针对于Android8.0(API 26),Android8.1(API 27),Android9(API 28),插件化所需要做的适配工作,参加以下3篇文章(第2版作为第23章会放入书中):

      Android插件化的兼容性(上):Android O的适配

      Android插件化的兼容性(中):Android P的适配

      Android插件化的兼容性(下):突破Android P中灰黑名单的限制

 

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

2018年8月第1版第1次印刷和第2次印刷

1)前言

比如说AssetsManager的addAssetPath方法,ActivityThread的currentActivityThread方法

 

这句话删除,举例不当。

 

2)第2章,P25

ActivityManagerNativ改为ActivityManagerNative

 

3)第3章,P73

如果只想获取类的所有public构造函数,就不能再使用Class的getConstructors方法了,而要使用getDeclaredConstructors方法。

 

这里写反了,订正如下:

如果只想获取类的所有public构造函数,只要调用Class的getConstructors方法就足够了。

 

4)第6章,P133

applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def file = output.outputFile
            output.outputFile = new File(file.parent,
                    "plugin1.apk")

            println("$buildDir/outputs/apk/")
            println("$rootDir/HostApp/src/main/assets")

            copy {
                from "$buildDir/outputs/apk/plugin1.apk"
                into "$rootDir/HostApp/src/main/assets"
            }
        }
}

 

上面这段脚本,有个瑕疵,要执行两次的插件项目中的assembleRelease命令,才能在HostApp的assets目录下生成plugin1.apk,订正如下:

 

assemble.doLast {
    android.applicationVariants.all { variant ->
        // Copy Release artifact to HostApp's assets and rename
        if (variant.name == "release") {
            variant.outputs.each { output ->
                File originFile = output.outputFile
                println originFile.absolutePath
                copy {
                    from originFile
                    into "$rootDir/HostApp/src/main/assets"
                    rename(originFile.name, "plugin1.apk")
                }
            }
        }
    }
}

 

接下来,执行插件项目的assemble命令,只要1次,即可生成在HostApp的assets目录下生成plugin1.apk。

 

5)第2章 P32

App和ASM频繁地向对方发送消息

 

修改为:App和AMS频繁地向对方发送消息

 

6) 第2章,P44

2.9.2

在Service中,通过AMM/AMP

订正为:

在Service中,通过AMN/AMP

 

7)第2章,P37

仍然是通过AMM/AMP

订正为:仍然是通过AMN/AMP

 

8)前言,P5

把android-pluginmgr设计为对Instrumentation的思想进行Hook

订正为: 把android-pluginmgr设计为对Instrumentation进行Hook

 

9)第18章,P287

ZeusStudy和1.6之间不应该有空格

 

10)第2章 P21

AndvoidManifest修改为AndroidManifest

 

11)第2章 P22

哪个,修改为那个

 

12)P101

图中,多了一个-

13)P102,第9行末尾,重写的逻辑,把英文句点改为中文句号。

 

14)P56

“主要逻辑都再此实现”中的“再此”应该为“在此”

 

15)113页

“对AMN的getDafault方法进行Hook”中“getDafault”应该为“getDefault”。default写错了

 

16)110页

“currentActivity-Thread”多了一个横线“-”

 

17)124页:

倒数第三行“会把asset目录中的插件”中的“asset目录”应该为“assets目录”。缺个s

 

18)

292页:“它有一个getsSring函数”中的“getsSring”应该为“getString”

 

19)

319页:“在Android Studio中建立一个过程”中的“过程”修改为“工程”。
 

 20)

320页:第2行:“同时在自定义的Class-Loader中”中的“Class-Loader”修改为“ClassLoader”。
 
21)
320页
第13行:“但是AndroidAndroid系统源码中也有一些类”中的“AndroidAndroid”修改为“Android“
 
22)235页
那么就通过10.3.2介绍的proxyCreateService方法
 
10.3.2改为14.4.2
 
23)238页
ServiceManager(省略了10.3.1介绍的proloadServices和10.3.2介绍的proxyCreateService)
10.3.2改为14.4.2
10.3.1改为14.4.3
preloadServices 改为preLoadServices
 
24)P97
RefInvoke.setFieldObject(sPackageManager,”sPackageManager”,proxy);
修改为
RefInvoke.setFieldObject(currentActivityThread,”sPackageManager”,proxy);
 
25)P100
图5-2中 Context/Contexztimpi  修改为Context/ContextImpl
 
26)P5
为张勇的DroidPlugin添加脚注:
https://github.com/Qihoo360/DroidPlugin
 
27)P194

B准备好数据,写到A要求的内存地址上,A就可以直接使用这些数据了
改为
A准备好数据,写到B要求的内存地址上,B就可以直接使用这些数据了
 
28)P196
在B1中
改为
在A1中
 
29)230
设计一个ProxyServiceManager的例子,
修改为
设计一个ProxyServiceManager的单例
 
30)235
这时候,不能把插件Service1换成ProxyService
修改为
这时候,不能把插件MyService1换成ProxyService
 
31)P245
 在sendBroadcastReceiver的时候
改为
sendBroadcast的时候
 
32) P25
AMN通过getDefault方法,从ServiceManager中取得一个名为activity的对象
改为
AMN通过getDefault方法,从ServiceManager中取得一个对象
 
33)P25
看到这里,你会发现AMP的startActivity方法,和AIDL的Proxy方法,是一模一样的
改为
看到这里,你会发现AMP扮演着AIDL中的Proxy的角色,我们在2.3节介绍过AIDL的Proxy类。
 
34) P42
删除以下两行代码

Intent intent = new Intent(this, MyService.class);

startService(intent);

35)P55,删除下面这2句话

在插件化编程中,我们反射ActivityThread获取apk包的信息,一般用于当前的宿主apk ,而不是插件apk

ApplicationPackageManager实现了IPackageManager.Stub

 
36) P181
dat改为data
 
 
 
 
posted @ 2018-07-16 10:30  包建强  Views(4621)  Comments(3Edit  收藏  举报