当前位置:网站首页>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
边栏推荐
- 安全(杂记)
- android studio创建平板模拟器方法
- Android Development - service application, timer implementation (thread + service)
- Analysis of the source code of ThinkPHP facade
- Chrome browser engine blink & V8
- From coding, network transmission, architecture design, Tencent cloud high quality, high availability real-time audio and video technology practice
- VisualStudio(Mac)安装过程笔记
- Fedora 33 Workstation 的新功能
- The choice of domain name of foreign trade self built website
- 真正拖垮你的,是沉没成本
猜你喜欢

Recommendation system, in-depth paper analysis gbdt + LR

嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:樊文凯

JVM学习(五) -执行子系统

Implement crud operation

Stack & queue (go) of data structure and algorithm series

libssl对CentOS登录的影响

使用CopyMemory API出现 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

Download Netease cloud music 10W + music library with Python

A simple ability determines whether you will learn!

What really drags you down is sunk costs
随机推荐
JVM学习(四)-垃圾回收器和内存分配
真正拖垮你的,是沉没成本
向北京集结!OpenI/O 2020启智开发者大会进入倒计时
jsliang 求职系列 - 08 - 手写 Promise
JVM学习(六)-内存模型和线程
git 删除iml文件
Mac terminal oh my Zsh + solarized configuration
关于无相互作用极化率的计算
SEO见风使舵,是对还是错?
[design pattern] Chapter 4: Builder mode is not so difficult
JVM学习(五) -执行子系统
Stack & queue (go) of data structure and algorithm series
Learning notes of nodejs
On the calculation of non interaction polarizability
嗯,查询滑动窗口最大值的这4种方法不错...
在企业的降本增效诉求下,Cube如何助力科盾业务容器化“一步到位”?
Explain Python input() function: get user input string
How to query by page after 10 billion level data is divided into tables?
Solve the problem of idea shortcut key Alt + insert invalid
百亿级数据分表后怎么分页查询?