当前位置:网站首页>AndroidStudio导入定制化的framework classess.jar AS 4.0.1版本亲测有效
AndroidStudio导入定制化的framework classess.jar AS 4.0.1版本亲测有效
2020-11-09 12:12:00 【osc_ydeb2o99】
有时候,我们需要调用系统framework层隐藏的接口,或者定制化的一些接口,那么在androidstudio不做特殊的配置和处理的话,默认优先引用android sdk api。那么就需要作如下配置:
步骤1: 在Moudle下的app下面增加libs文件夹,并将自己的jar包放在里面。
--app
--libs
---framework.jar
步骤2:在Moudle下的app目录下的build.gradle文件增加如下红色代码。
dependencies {
compileOnly files('libs/framework.jar')
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
preBuild {
doLast {
def imlFile = file(project.name + ".iml")
println 'Change ' + project.name + '.iml order'
try {
def parsedXml = (new XmlParser()).parse(imlFile)
def jdkNode = parsedXml.component[1].orderEntry.find { it.'@type' == 'jdk' }
parsedXml.component[1].remove(jdkNode)
def sdkString = "Android API " + android.compileSdkVersion.substring("android-".length()) + " Platform"
new Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': sdkString, 'jdkType': 'Android SDK'])
groovy.xml.XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile))
} catch (FileNotFoundException e) {
// nop, iml not found
}
}
}
其实上面这个preBuild{...} 主要就是将默认的android sdk 放到最后面,这样就自己的framework.jar就能优先引用了。
步骤3: 在project根目录下的build.gradle文件下增加如下代码:
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs.add('-Xbootclasspath/p:app\\libs\\framework.jar')
}
}
repositories {
google()
jcenter()
}
}
上面步骤设置好之后,刷新工程,重新编译,可能会出现运行时报错,提示odex超出65536,一般需要加上如下设置。
在Module的app下面的build.gradle里找到defaultConfi加入multiDexEnabled = true
并在dependencies里添加
implementation 'com.android.support:multidex:1.0.0'
版权声明
本文为[osc_ydeb2o99]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4387121/blog/4709325
边栏推荐
- Kubernetes业务日志收集与监控
- Kubernetes business log collection and monitoring
- 你不好奇 CPU 是如何执行任务的吗?
- List of wechat video Number broadcasters October 2020
- 在企业的降本增效诉求下,Cube如何助力科盾业务容器化“一步到位”?
- Understanding data structures starts with this article~
- Dynamo: a typical distributed system analysis
- Open source projects for beginners on GitHub (Python)
- Mac terminal oh my Zsh + solarized configuration
- SQL Chapter 2 Chapter 3
猜你喜欢
开源ERP招聘了
The third way to realize webrtc in embedded devices
Setting up a proxy for the WGet command
接口测试如何在post请求中传递文件
Handwriting Koa.js Source code
解决IDEA快捷键 Alt+Insert 失效的问题
A simple ability determines whether you will learn!
Learning notes of nodejs
[design pattern] Chapter 4: Builder mode is not so difficult
嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:樊文凯
随机推荐
Nine kinds of distributed primary key ID generation schemes of sub database and sub table are quite comprehensive
inet_pton()和inet_ntop()函数详解
Kubernetes业务日志收集与监控
零基础IM开发入门(四):什么是IM系统的消息时序一致性?
Handwriting Koa.js Source code
医疗项目管理的三种实用技巧
用一种简单的方式实现终端文字粘贴板
EFF 认为 RIAA 正在“滥用 DMCA”来关闭 YouTube-DL
How to ensure that messages are not consumed repeatedly? (how to ensure the idempotent of message consumption)
SQL第二章第三章
百亿级数据分表后怎么分页查询?
SQL Chapter 2 Chapter 3
解决IDEA快捷键 Alt+Insert 失效的问题
使用流读文件写文件处理大文件
微信视频号播主排行榜2020年10月
使用rem,做到屏幕缩放时,字体大小随之改变
未来中国电信将把云计算服务打造成为中国电信的主业
详解Python input()函数:获取用户输入的字符串
线上服务的FGC问题排查,看这篇就够了!
for与for...in、for Each和map和for of