Android studio jar包生成方式

本文详细介绍如何在Android Studio中创建模块并生成jar包。包括配置lintOptions避免构建错误、定义Gradle任务来打包和重命名jar文件。还提供了解决配置问题的方法,确保能够成功生成jar包。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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






评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值