将源码中的应用独立流程

源码中的应用有时候我们需要将其独立出来达到一定的开发目的,下面以camera为例来讲解一下独立的过程

Camera 应用独立
为什么独立
Android N 使用了 Ninja 编译系统,旨在加快编译速度,但是对内存要求也变高,编译过程中会占用大量内
存,这就导致在编译服务器上,会出现多人同时编译抢占内存资源的情况,这种情况下单模块的编译时间可
能从几分钟增至半小时以上。
UI 任务增加,UI 的微调需要多次运行到真机上看效果。
优点:加快编译速度;独立于项目,便于管理;最重要的是可以在 AS 上编译后,我们就可以运用 AS 的各种
强大的功能(如 Lint、xml预览)及插件(如 FindBugs)。
Problems & Solutions
P:原生 SDK 与平台 frameworks 代码差异
S:制作含平台代码的 SDK, 方法:
分别用解压工具打开
out\target\common\obj\JAVA_LIBRARIES\framework_intermediates\classes.jar(左侧)

sdk\platforms\android-23\android.jar(右侧)
然后将 左侧 所有内容 复制黏贴 到 右侧,然后保存即可
P:资源(Resources )重复
S:根据 AS 的 Build 面板中提示的错误信息,逐条删除重复资源(目前没有找到更快捷的方式)
P:依赖的 .so 文件缺失
S:将 Android.mk 中 LOCAL_REQUIRED_MODULES 依赖的 .so 放到应用 lib 对应的 ABI 目录下
P:远程依赖的版本选择
S:根据 AS 的 Build 面板中提示的错误信息,找到缺失类的包名,然后在 Maven Central Repository Search 上搜
索,找到对应版本,在 dependencies 中添加即可,例:
dependencies { compile 'com.adobe.xmp:xmpcore:5.1.2' }
注意:compile(api)、provided(compileOnly)、implementation 的使用选择 !依赖命令解释
P:无法引用 /system/lib/ 下的 .so
S:将 /system/lib/ 下无法引用的 .so 通过 adb pull 出来,然后放到应用 lib 对应的 ABI 目录下(目前没有
找到其他解决方案)
P:为什么将 frameworks\ex\camera2\ 目录作为应用 srcFolder 参与编译
S: Android.mk 中 LOCAL_STATIC_JAVA_LIBRARIES += android-ex-camera2-portability 对此目录代码
有依赖,且便于应用独立后代码修改
P:独立后应用体积增加
S: build.gradle 配置
如何独立
主要通过修改 build.gradle 配置
defaultConfig {
resConfigs 'hdpi'// 只打包 hdpi 资源
ndk{
abiFilters 'armeabi-v7a'// 通过 “减少其他 CPU 类型支持的 SO 库” 来减少 APK 的体积
}
}
buildTypes {
release {
minifyEnabled true// 是否进行混淆
shrinkResources true// 去除无用资源
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-
rules.pro'// 混淆文件的位置
}
}
// Top-level build file where you can add configuration options common to all sub-
projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
allprojects {
repositories {
jcenter()
}
}
// app config
apply plugin: 'com.android.application'
android {
def compileSdkVersionInt = 26
compileSdkVersion = compileSdkVersionInt
buildToolsVersion '25.0.2'
defaultConfig {
applicationId "com.android.camera2"
minSdkVersion 22
targetSdkVersion 26
versionCode getCurrentDate() as int
versionName "2.0.0" + "." + getCurrentDate()
multiDexEnabled true
resConfigs 'hdpi'
ndk{
abiFilters 'armeabi-v7a'
}
}
//签名
signingConfigs {
main {
storeFile file("./platform.jks") //签名文件路径
storePassword "multimedia"
keyAlias "multimedia"
keyPassword "multimedia"
}
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
signingConfig signingConfigs.main//签名
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true// 是否进行混淆
shrinkResources true
signingConfig signingConfigs.main//签名
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'//
混淆文件的位置
}
}
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
if (compileSdkVersionInt >= 26) {
useLibrary 'org.apache.http.legacy'
}
sourceSets {
main {
def manifestFile = file('AndroidManifest.xml')
def srcFolder = [
'src',
'src_pd',
'src_pd_gcam',
"frameworks/ex/camera2/portability/src",
"frameworks/ex/camera2/public/src",
"frameworks/ex/camera2/utils/src",
"frameworks/ex/vendor/camera2/portability/src"
]
def resFolder = [
'res',
'res_filter',
'res_filter_arc',
'res_filter_sprd',
'res_p',
'res_modify',
'res_transsion'
]
def assetsFolder = [
]
def jniFolder = [
'libs',
]
manifest.srcFile manifestFile
java.srcDirs = srcFolder
resources.srcDirs = srcFolder
aidl.srcDirs = srcFolder
renderscript.srcDirs = srcFolder
res.srcDirs = resFolder
assets.srcDirs = assetsFolder
//jni.srcDirs = jniFolder
jniLibs.srcDirs = jniFolder
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
//add this for Execution failed for task ':mockableAndroidJar'
tasks.whenTaskAdded { task ->
if (task.name.contains("mockableAndroidJar")) {
task.enabled = false
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:25.0.0'
compile 'com.android.support:support-v13:25.0.0'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.adobe.xmp:xmpcore:5.1.2'
compile 'com.github.bumptech.glide:glide:3.5.2'
//compile 'com.google.zxing:core:3.3.0'
compile 'com.google.guava:guava:19.0'
compile 'com.google.code.findbugs:jsr305:3.0.2'
compile 'com.android.support:multidex:1.0.1'
}
def getCurrentDate() {
def now = new Date().format('yyyyMMddHH');
return now;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值