1.Android引入依赖的多种方式 2.多平台私服搭建 3.创建和依赖自己的代码仓库
AS切换project视图>新建libs目录(高版本AS默认存在libs目录)>copy jar 包>add as library
下面以我开源的支付宝以及微信app支付项目为例引入相关的jar
方式一:add as library 直接使用Gradle-Sync Nowimport module>Project Structure>选择对应的Module>module dependent 我们知道jar包是不能引入资源文件的,如果已module模式引入资源文件同样可以使用。
打开Project Structure-方式1 打开Project Structure-方式2 Project StructureNew Module >Android Library>实现包功能并生成aar文件
构建生成aar以上两种引入jar依赖弊端就是jar包升级之后需要Copy替换换新的jar并修改对应的配置文件。
从仓库中下载引用 找到jar对应的build.gradle>compile(jcenter、mavencenter、mavenlocal)>通过Nexue搭建私服
https://bintray.com/bintray/jcenter http://search.maven.org http://www.sonatype.org
部分网站访问需要科学上网,你懂的哈
Android Studio最新版默认使用的是jcenter,好处就是jar包升级自需要修改版本号,构建项目会自动从仓库中下载(只会下载一次,下载以后会从本地引入)。
AS默认使用的是 jcenter下面以引入retrofit为例
引入仓库中的jar- retrofit或者直接在对应项目Module的build.gradle中dependencies节点添加
compile 'com.squareup.retrofit2:retrofit:2.1.0' 最终配置相互依赖的包也会下载下来,retrofit依赖okhttp依赖ikoi
相互依赖的包也会下载下来http://www.sonatype.org
http://books.sonatype.com/nexus-book/3.0/reference/index.html
Note: The GUI installer distribution development is suspended and is no longer an install option until further notice.
Nexus Repository Manager 3.1.0-04 开始并没有提供GUI的安装程序。建议JDK使用1.8版本。
官网首页 选择最新版本Nexus3 下载安装介绍资料 http://books.sonatype.com/nexus-book/3.0/reference/install.html#installation-archive
解压下载的nexus $ tar xvzf nexus-3.0.2-02-mac.tgz $ tar xvzf nexus-3.0.2-02-unix.tar.gz
The bin folder contains the generic startup scripts for Unix-like platforms called nexus. The Windows platform equivalent is called nexus.exe. To start the repository manager from the bin folder on a Unix-like platform like Linux use ./nexus run The equivalent invocation on Windows requires a / in front of the run and any other commands. nexus.exe /run
简单解释就是Mac、Linux平台使用./nexus run Window平台使用 nexus.exe /run 运行Nexus Repository Manager
Mac
OSX archive下载解压Linux
Unix archive解压进bin目录,执行 ./nexus run
运行Nexus服务Nexus Repository Manager依赖的是Java开发环境,最新版JDK得1.8或者以上
提示设置INSTALL4J_JAVA_HOME_OVERRIDE在nexus的bin目录修改nexus,设置INSTALL4J_JAVA_HOME_OVERRIDE
修改nexus1 配置默认的JAVA_HOME 启动Nexus关闭防火墙 默认端口8081 systemctl stop firewalld
参考质料: http://books.sonatype.com/nexus-book/3.0/reference/install.html#installation-java
1、创建用户 首先使用管理员密码登陆到Nexus私服并添加用户
登录 创建用户使用新创建的用户登录Nexus并创建仓库
创建仓库1 创建仓库2 创建仓库3 创建完成第一 在项目级别的build.gradle中的allprojects下repositories节点添加mavenLocal()
配置本地maven引用第二 在Lib Module级别的build.gradle中添加maven插件apply plugin: 'maven'
添加maven插件第三 在Lib Module级别的build.gradle中android节点添加上传行为
定义上传行为解析: compile 'com.android.support:appcompat-v7:24.2.1' pom.version = "24.2.1" pom.artifactId = "appcompat-v7" pom.groupId ="com.android.support"
//定义上传行为 uploadArchives { //仓库基于maven repositories.mavenDeployer { //配置上传的url repository(url: "http://192.168.1.100:8081/repository/com.javen205/") { authentication(userName: "javen", password: "javen205") } pom.version = "0.0.1" pom.artifactId = "JPay" pom.groupId = "com.javen205" } }第四 使用Gradle插件上传aar到Maven私服
点击uploadArchives自动上传
上传aar到服务器 刷新页面重新查看在需要依赖Module的build.gradle中添加如下节点,其中URL就是上文中创建仓库的url
allprojects { repositories { maven { url "http://192.168.1.100:8081/repository/com.javen205/" } } } compile 'com.javen205:JPay:0.0.1'查看 External Libraries
查看上面上传的aar应用成功推荐阅读 Android Studio 上传aar(Library)到JCenter Android版-支付宝APP支付 Android版-微信APP支付 支付宝Wap支付你了解多少? 一张二维码集成微信、支付宝支付
安利时间: JPay是对微信App支付、支付宝App支付的二次封装,对外提供一个相对简单的接口以及支付结果的回调
极速开发微信公众号是对微信公众平台接口的二次封装。包括开发者模式、事件回调监听、微信模板消息、微信客服消息、自定义菜单、微信支付、素材管理等
如遇到问题欢迎留言交流
记录学习的点滴,以此勉励不断奋斗的自己✌️✌️✌️ 如果对你有帮助记得点喜欢告诉我