Android Framework应用定制开发"/>
Android Framework应用定制开发
1.Android Framework定制API
1.1.增加API编译
一般增加Java API后会编译报错,根据如下提示执行(Android Q为例)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 theerrors above.2. You can update current.txt by executing the following command:make api-stubs-docs-update-current-apiTo submit the revised current.txt to the main Android repository,you will need approval.
执行命令
make api-stubs-docs-update-current-api
1.2.生成系统签名文件keystore
(1)找到平台签名文件“platform.pk8”和“platform.x509.pem”
文件位置 android/build/target/product/security/
(2)把pkcs8格式的私钥转化成pkcs12格式:
openssl pkcs8 -in platform.pk8 -inform DER -outform PEM -out shared.priv.pem -nocrypt
(3)把x509.pem公钥转换成pkcs12格式
openssl pkcs12 -export -in platform.x509.pem -inkey shared.priv.pem -out shared.pk12 -name xxx-androidkey密码都是(根据需要自行定义):xxxandroid
(4)生成platform.keystore
keytool -importkeystore -deststorepass xxxandroid -destkeypass xxxandroid -destkeystore platform.keystore -srckeystore shared.pk12 -srcstoretype PKCS12 -srcstorepass xxxandroid -alias xxx-androidkey
最终在同一个目录下生成platform.keystore文件。
2.Android Studio应用适配
2.1.源码编译的framework.jar
android 系统应用二次开发的导入包,生成位置
./out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar
可以自行重命名为framework.jar
2.2.Android Studio引入源码编译的包
2.2.1.系统签名
(1)在 AndroidMainfest.xml 中显示添加系统权限
<manifest xmlns:android=""package="com.ymf.demoapp"android:sharedUserId="android.uid.system">
(2)选择生成platform.keystore添加到android studio的Store File并填入密码
2.2.2.引入framework.jar
(1)将拷出来的jar文件命名为framework.jar或androidXX.jar,放在Module的libs下面
(2)右键framework.jar,选择“Add As Library”
原来无法索引的就会找到
2.2.3.编译调试
2.2.1.引入framework.jar后造成的超方法数
Caused by: java.lang.ArrayIndexOutOfBoundsException: 65535
或者
Execution failed for task ':app:mergeExtDexDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade> java.lang.ArrayIndexOutOfBoundsException: Index 65535 out of bounds for length 61483* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
这个异常可以理解为,总函数数量超出java虚拟机的限制.
解决方案:修改framework.jar的编译方式
在build.gradle中将:implementation files(‘libs/framework.jar’)的引用方式更换为compileOnly files(‘libs/framework.jar’),不在Android Studio的选框里选择,因为没有这个选项!
后者的含义为只编译不集成进apk或者jar包中, 相当于编译的时候有framework.jar环境,但是却不会将framework.jar的相关引用编译进jar或者apk中.
2.2.2.引入framework.jar后还是默认索引的AS的android.jar
可以在模块的build.gradle中添加如下代码,就会优先索引framework.jar
gradle.projectsEvaluated {tasks.withType(JavaCompile) {Set<File> fileSet = options.bootstrapClasspath.getFiles()List<File> newFileList = new ArrayList<>();//建议用绝对位置newFileList.add(new File("libs/framework.jar"))newFileList.addAll(fileSet)options.bootstrapClasspath = files(newFileList.toArray())//或者//optionspilerArgs.add('-Xbootclasspath/p:app\\libs\\framework.jar')}
}
更多推荐
Android Framework应用定制开发
发布评论