Android 学习

Android aar 拷贝到sdk一起打包成新的aar

2018-12-25  本文已影响0人  酥酥肉

概述

1、需要将一个aar包与项目产生的aar包合并成一个,其中项目是源码
2、项目是源码

解压依赖aar

解压aar,利用build,gradle

//很重要,因为解压后如果copy资源文件到raw里,这时R文件已经编译了,所以要在R文件编译之前执行此操作
tssks.withType(com.android.build.gradle.tasks.NdkCompile) {
      compileTask -> compileTask.dependsOn(unzipAAR)
}
task unzipAAR(type: Exec) {
    commandLine 'unzip', '-o',    file("libs/xxxx.aar").getAbsolutePath(), '-d', file('MyAAR')
}

unzipAAR.doLast {
       copy {
           from 'MyAAR/res/raw'
           into 'src/main/res/raw'
       }
      
        copy {
          from 'MyAAR/classes.jar'
          into 'libs/jars/'
          rename { String fileName -> "xxxx.jar"}
      }

//这里libs文件夹下只有一个jar
        copy {
          from 'MyAAR/libs/'
          into 'libs/jars/'
          rename { String fileName -> "xxxx.jar"}
    }
}
tasks.withType(JavaCompile) {
   compileTask -> compileTask.dependsOn unzipAAR
}

如果有ndk编译,so的copy动作要放在ndk之后

task copyJNIso (type: Copy) {
    from 'MyAAR/jni'
    into 'src/main/libs'
}

tasks.withType(JavaCompile) {
   compileTask -> compileTask.dependsOn copyJNIso 
}

copyJNIso .mustRunAfter 'ndkBuild'

清除操作

创建一个makeclean.sh文件,可以是libs/makeclean.sh
build.gradle文件还要添加

task makeClean(type: Exec) {
    executable 'sh'
    args "libs/makeclean.sh"
}

clean.dependsOn 'makeClean'

makeclean.sh
···

!/bin/sh

rm -rf MyAAR
rm -rf libs/jars/xxxx.jar
rm-rf libs/jars/xxxxx.jar
rm -rf src/main/res/raw

···

上一篇下一篇

猜你喜欢

热点阅读