1)全書70個代碼例子中,涉及到插件的例子,請先assemble插件的項目,這會在HostApp項目中生成assets目錄,並在該目錄下plugin1.apk。這樣,HostApp才能正常運行。html
2)本書基於Android6.0(API level 23)的源碼進行分析,本書的代碼在Android7.0(API level 24)手機上測試都是能正常工做的。對於Android 7.0以上版本,有些插件化的解決方案,已通過時了,好比AMN的gDefault字段。android
3)針對於Android8.0(API 26),Android8.1(API 27),Android9(API 28),插件化所須要作的適配工做,參加如下3篇文章(第2版做爲第23章會放入書中):git
Android插件化的兼容性(上):Android O的適配github
Android插件化的兼容性(中):Android P的適配編程
Android插件化的兼容性(下):突破Android P中灰黑名單的限制app
-----------------------------------------------------------函數
1)前言測試
好比說AssetsManager的addAssetPath方法,ActivityThread的currentActivityThread方法。ui
這句話刪除,舉例不當。this
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)
20)
Intent intent = new Intent(this, MyService.class);
startService(intent);
在插件化編程中,咱們反射ActivityThread獲取apk包的信息,通常用於當前的宿主apk ,而不是插件apk。
ApplicationPackageManager實現了IPackageManager.Stub。