Android studio jar包生成方式
1.增加 module
File --> new --> new module -->android Library 把需要生成jar包的文件copy到 Main中 。
项目的目录结构为:
1.1 在你所建立的module build.gradle中 添加 lintOptions 放在Android
括号内
}
lintOptions {
abortOnError false
}
}
build.gradle中 添加,放在 Android 括号外
task makeJar(type : Copy) {
delete 'build/libs/mylibrary.jar' // 删除已经存在的 jar 包
from('build/intermediates/bundles/release/' )// 从该目录下加载要打包的文件
into('build/libs/' )//jar 包的保存目录
include('classes.jar' )// 设置过滤,只打包 classes 文件
rename('classes.jar' , 'cnrlibrary.jar' )// 重命名, mylibrary.jar 根据自己的需求设置
}
makeJar.dependsOn(build)
1.2 执行 ./gradlew makeJar
这时候你可能会遇到一个错误 A problem occurred configuring root project 'Multi-threadedDownload'.
> Could not resolve all files for configuration ':classpath'.
1.3 解决办法 -->
感谢 -- > https://stackoverflow.com/questions/25994163/could-not-resolve-all-dependencies-for-configuration-classpath
Right im not sure if it will work for others but worked for me.
I changed proxyPort to 8080 and used jcenter instead of Maven. But i had to apply expeption to use HTTP instead of HTTPS. This is what i have in
my gradle.build for build script and allprojects
buildscript {
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
}
allprojects {
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
}
1.4 最后在执行./gradlew makeJar