当前位置:网站首页>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
边栏推荐
猜你喜欢
PAT_甲级_1074 Reversing Linked List
【golang】GC详解
Adobe Experience Design /Xd 2020软件安装包(附安装教程)
vscode 插件配置指北
JVM学习(五) -执行子系统
JVM learning (6) - memory model and thread
外贸自建网站域名的选择— Namesilo 域名购买
An attempt to read or write to protected memory occurred using the CopyMemory API. This usually indicates that other memory is corrupted.
After SQL group query, get the first n records of each group
Kubernetes business log collection and monitoring
随机推荐
Large scale project Objective-C - nsurlsession access SMS verification code application example sharing
分库分表的 9种分布式主键ID 生成方案,挺全乎的
Visit Jingdong | members of Youth Innovation Alliance of China Academy of space technology visit Jingdong headquarters
The middle stage of vivo Monkey King activity
JVM learning (4) - garbage collector and memory allocation
Mapstructure detoxifies object mapping
走进京东 | 中国空间技术研究院青年创新联盟成员莅临参观京东总部
在企业的降本增效诉求下,Cube如何助力科盾业务容器化“一步到位”?
一个简单的能力,决定你是否会学习!
SQL statement to achieve the number of daffodils
On the calculation of non interaction polarizability
未来中国电信将把云计算服务打造成为中国电信的主业
为wget命令设置代理
Wechat circle
SQL第二章第三章
Reread reconstruction
嗯,查询滑动窗口最大值的这4种方法不错....
libssl对CentOS登录的影响
Three practical skills of Medical Project Management
ThinkPHP门面源码解析