当前位置:网站首页>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
边栏推荐
- jsliang 求职系列 - 08 - 手写 Promise
- 嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:樊文凯
- PAT_甲级_1074 Reversing Linked List
- 未来中国电信将把云计算服务打造成为中国电信的主业
- SQL语句实现水仙花数求取
- 使用CopyMemory API出现 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
- Handwriting Koa.js Source code
- 嗯,查询滑动窗口最大值的这4种方法不错....
- From coding, network transmission, architecture design, Tencent cloud high quality, high availability real-time audio and video technology practice
- Analysis of the source code of ThinkPHP facade
猜你喜欢
随机推荐
Kubernetes business log collection and monitoring
vscode 插件配置指北
Android Development - service application, timer implementation (thread + service)
el-table动态表头
After SQL group query, get the first n records of each group
nodejs学习笔记(慕课网nodejs从零开发web Server博客项目)
Reading design patterns adapter patterns
Handwriting Koa.js Source code
Large scale project Objective-C - nsurlsession access SMS verification code application example sharing
关于无相互作用极化率的计算
ThinkPHP门面源码解析
Mapstructure detoxifies object mapping
Android权限大全
In the future, China Telecom will make cloud computing service the main business of China Telecom
SHOW PROFILE分析SQL语句性能开销
解决IDEA快捷键 Alt+Insert 失效的问题
Interface tests how to pass files in post requests
共创爆款休闲游戏 “2020 Ohayoo游戏开发者沙龙”北京站报名开启
Aren't you curious about how the CPU performs tasks?
微信圈子







