当前位置:网站首页>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
边栏推荐
- Dynamo: a typical distributed system analysis
- What really drags you down is sunk costs
- Android权限大全
- 如何用函数框架快速开发大型 Web 应用 | 实战
- Looking for better dynamic getter and setter solutions
- PAT_甲级_1074 Reversing Linked List
- inet_ Pton () and INET_ Detailed explanation of ntop() function
- Sql分组查询后取每组的前N条记录
- el-table动态表头
- Understanding data structures starts with this article~
猜你喜欢
Open source projects for beginners on GitHub (Python)
Learning notes of nodejs
Fedora 33 Workstation 的新功能
Is SEO right or wrong?
Looking for better dynamic getter and setter solutions
FGC online service troubleshooting, this is enough!
android studio创建平板模拟器方法
Visual Studio (MAC) installation process notes
配置交换机Trunk接口流量本地优先转发(集群/堆叠)
Configure switch trunk interface traffic local priority forwarding (cluster / stack)
随机推荐
nodejs学习笔记(慕课网nodejs从零开发web Server博客项目)
Mac 终端(terminal) oh-my-zsh+solarized配置
在企业的降本增效诉求下,Cube如何助力科盾业务容器化“一步到位”?
Review of hot spots of last week (11.2-11.8)
El table dynamic header
如何用函数框架快速开发大型 Web 应用 | 实战
An attempt to read or write to protected memory occurred using the CopyMemory API. This usually indicates that other memory is corrupted.
真正拖垮你的,是沉没成本
Kubernetes业务日志收集与监控
EFF 认为 RIAA 正在“滥用 DMCA”来关闭 YouTube-DL
Looking for better dynamic getter and setter solutions
The choice of domain name of foreign trade self built website
[design pattern] Chapter 4: Builder mode is not so difficult
从编码、网络传输、架构设计揭秘腾讯云高质量、高可用实时音视频技术实践...
ThinkPHP门面源码解析
el-table动态表头
Jsliang job series - 08 - handwritten promise
Interview summary on November 7, 2020 (interview 12K)
As a user, you can't get rid of the portrait!
Handwritten digital image recognition convolution neural network