Android使用kts发布aar到JitPack仓库

news2024/10/7 8:22:09

Android使用kts发布aar到JitPack

之前做过sdk开发,需要将仓库上传到maven、JitPack或JCenter,但是JCenter已停止维护,本文是讲解上传到JitPack的方式,使用KTS语法,记录使用过程中遇到的一些坑.相信Groovy的方式是大家经常使用的,但是KTS语法应该使用很少,项目着急上线的话遇到问题不好解决,于是为了稳定肯定是Groovy为首选,这里就不纠结了,直接上代码.

1.创建项目(library方式):

由于之前用鸿神的wanandrdoi接口api写过简单demo,所以本文的aar还是采用wanandrdoid的接口请求api

在这里插入图片描述

2.修改项目build.gradle依赖:

plugins {
//alias(libs.plugins.androidApplication)
alias(libs.plugins.androidLibrary)
alias(libs.plugins.jetbrainsKotlinAndroid)
alias(libs.plugins.mavenPublish)
}

group = “om.example.wanandroidsdk”
version = “1.0.0”

afterEvaluate {
publishing {
publications {
// Creates a Maven publication called “release”.
create(“release”) {
// Applies the component for the release build variant.
// from(components[“release”])
// You can then customize attributes of the publication as shown below.
groupId = (group.toString())
artifactId = “wanandroidsdk-kts”
version = version
}
}
}
}

android {
namespace = “com.example.wanandroidsdk”
compileSdk = 34

defaultConfig {
    //applicationId = "com.example.wanandroidsdk"
    minSdk = 24
    targetSdk = 34

/* versionCode = 1
versionName = “1.0”*/

    testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
    release {
        isMinifyEnabled = false
        //isDebuggable = false

// signingConfig = signingConfigs.getByName(“release”)
proguardFiles(
getDefaultProguardFile(“proguard-android-optimize.txt”),
“proguard-rules.pro”
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = “1.8”
}
}

dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
implementation(libs.okhttp)
implementation(libs.logging.interceptor)
implementation(libs.utilcodex)
implementation(libs.rxjava)
implementation(libs.retrofit)
implementation(libs.adapter.rxjava2)
implementation(libs.converter.scalars)
implementation(libs.converter.gson)
implementation(libs.androidx.core.ktx)
}

在这里插入图片描述

3.修改app目录下的依赖:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.androidApplication).apply(false)
alias(libs.plugins.androidLibrary).apply(false)
alias(libs.plugins.jetbrainsKotlinAndroid) apply false
alias(libs.plugins.mavenPublish) apply false
}
在这里插入图片描述

4.添加项目统一依赖管理:

[versions]
agp = "8.1.4"
kotlin = "1.9.0"
coreKtx = "1.10.1"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
appcompat = "1.6.1"
material = "1.10.0"
activity = "1.8.0"
constraintlayout = "2.1.4"
okhttp = "4.11.0"
logging-interceptor = "4.10.0"
utilcodex = "1.31.1"
rxjava = "2.2.21"
retrofit = "2.9.0"
adapter-rxjava2 = "2.9.0"
converter-scalars = "2.4.0"
converter-gson = "2.9.0"


[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
okhttp = {group = "com.squareup.okhttp3",name = "okhttp",version.ref = "okhttp"}
logging-interceptor = {group = "com.squareup.okhttp3",name = "logging-interceptor",version.ref = "logging-interceptor"}
utilcodex = {group = "com.blankj",name = "utilcodex",version.ref = "utilcodex"}
rxjava = {group = "io.reactivex.rxjava2",name = "rxjava",version.ref = "rxjava"}
retrofit = {group = "com.squareup.retrofit2",name = "retrofit",version.ref = "retrofit"}
adapter-rxjava2 = {group = "com.squareup.retrofit2",name = "adapter-rxjava2",version.ref = "adapter-rxjava2"}
converter-scalars = {group = "com.squareup.retrofit2",name = "converter-scalars",version.ref = "converter-scalars"}
converter-gson = {group = "com.squareup.retrofit2",name = "converter-gson",version.ref = "converter-gson"}

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
androidLibrary = { id = "com.android.library", version.ref = "agp" }
jetbrainsKotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.28.0" }

5.设置仓库名称、版本号:

由于我是之前设置过,这里直接上代码
group = “om.example.wanandroidsdk”
version = “1.0.0”

afterEvaluate {
publishing {
publications {
// Creates a Maven publication called “release”.
create(“release”) {
// Applies the component for the release build variant.
// from(components[“release”])
// You can then customize attributes of the publication as shown below.
groupId = (group.toString())
artifactId = “wanandroidsdk-kts”
version = version
}
}
}
}在这里插入图片描述

6.上传代码到github仓库:

使用sourcetree、git命令行等工具都可以,这里我使用的是SourceTree,具体过程就不细讲了相信大家都会,示例截图如下:

在这里插入图片描述

7.创建Release、Tag及版本:

点击截图所示的Tags

在这里插入图片描述

在这里插入图片描述

由于我之前测试过好几个版本所以这里的tag是v1.0.12

在这里插入图片描述

8.提交仓库到JitPack

在这里插入图片描述

9.打开JitPack

9.1:我的仓库地址:NingJinBo/WanAndroidSdk

9.2:将仓库地址复制到这个输入框中,然后点击Look Up,

在这里插入图片描述

9.3:然后会出现你的发布版本,再点击Get it.

现在提交成功了,再点击一下这个Get it。会自动向下滑,然后会告诉你怎么样在项目中使用这个依赖库。

在这里插入图片描述

10.测试我的依赖库:

10.1 在测试项目添加jitpack镜像配置

maven { url 'https://jitpack.io' }

10.2 引入我的aar仓库

implementation 'com.github.NingJinBo:wanandroidsdk:v1.0.19'

10.3 添加测试代码
package com.example.wansdktest

import android.os.Bundle
import android.util.Log
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.Glide
import com.example.wanandroidsdk.bean.EasyDataBean
import com.example.wanandroidsdk.http.WanHttpCallBack
import com.example.wanandroidsdk.http.WanHttpUtil

class MainActivity : AppCompatActivity() {
private val TAG = “okhttp”
private val textView :TextView by lazy { findViewById(R.id.tv_test) }
private val iv :ImageView by lazy { findViewById(R.id.iv_test) }

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    getData()
}

private fun getData() {
    WanHttpUtil.getBanner(object : WanHttpCallBack {
        override fun onResponse(list: List<EasyDataBean>): Boolean {
            Log.d(TAG, " ===请求成功数据为=== " + list[0].imagePath)
            textView.text = list[0].title
            Glide.with(this@MainActivity).load(list[0].imagePath).into(iv)
            return true
        }

        override fun onFailure(s: String): Boolean {
            return true
        }
    })
}

}

在这里插入图片描述

11.日志打印如下:

在这里插入图片描述

在这里插入图片描述

12.实现效果截图:

在这里插入图片描述

13.总结:

以上就是今天的内容,使用kts语法上传aar到JitPack

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1642257.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

力扣每日一题106:从中序与后序遍历序列构造二叉树

题目 中等 相关标签 相关企业 给定两个整数数组 inorder 和 postorder &#xff0c;其中 inorder 是二叉树的中序遍历&#xff0c; postorder 是同一棵树的后序遍历&#xff0c;请你构造并返回这颗 二叉树 。 示例 1: 输入&#xff1a;inorder [9,3,15,20,7], postorder …

R语言学习—6—多元相关与回归分析

1、引子 xc(171,175,159,155,152,158,154,164,168,166,159,164) #身高 yc(57,64,41,38,35,44,41,51,57,49,47,46) #体重 par(marc(5,4,2,1)) #设定图距离画布边缘的距离&#xff1a;下5&#xff0c;左4&#xff0c;上2&#xff0c;右1 plot(x,y) 2、相关…

Web API之DOM

DOM 一.认识DOM二.获取元素三.事件基础四.操作元素(1).改变元素内容(2).修改元素属性(str、herf、id、alt、title&#xff09;(3).修改表单属性(4).修改样式属性操作(5).小结 五.一些思想(1).排他思想(2).自定义属性的操作 六.节点操作1.认识2.节点层级关系3.创建和添加、删除、…

PR2019软件下载教程

打开下载网址&#xff1a;rjctx.com 选择Premiere&#xff1a; 选择PR2019&#xff0c;并点击&#xff1a; 拉到最后&#xff0c;选择百度网盘下载&#xff1a; 下载到本地。 二&#xff0c;软件安装 解压缩后&#xff0c;双击set_up 选择位置后&#xff0c;进行安装&…

直播素材安卓情侣飞行棋v2.22 仿dofm 支持自定义模式—可用直播素材

一个情侣间增进友谊的小游戏非常好玩&#xff0c;适合男孩女孩之间增进感情&#xff01;快和你暗恋的女孩一块玩吧&#xff0c;极速升温 永久免费&#xff01;解锁激活码内容全部畅玩&#xff01;全网最强超级给力&#xff01;真人说书音频 网盘自动获取 链接&#xff1a;http…

Monorepo(单体仓库)与MultiRepo(多仓库): Monorepo 单体仓库开发策略与实践指南

&#x1f31f; 引言 在软件开发的浩瀚宇宙里&#xff0c;选择合适的代码管理方式是构建高效开发环境的关键一步。今天&#xff0c;我们将深入探讨两大策略——Monorepo&#xff08;单体仓库&#xff09;与MultiRepo&#xff08;多仓库&#xff09;&#xff0c;并通过使用现代化…

ThreeJS:两种场景雾

雾 ThreeJS提供了Fog类&#xff0c;用于创建线性雾的效果&#xff1b;提供了FogExp2类&#xff0c;用于实现指数雾的效果。 雾效果常用于模拟真实世界中视觉深度递减的效果&#xff0c;也可以用于创建某些艺术效果。即&#xff1a;当物体距离观察者越远&#xff0c;雾就越密&am…

Windows系统下安装Mosquitto的步骤(6)

接前一篇文章&#xff1a;Windows系统下安装Mosquitto的步骤&#xff08;5&#xff09; 本文内容参考&#xff1a; Windows下搭建MQTT服务器_mqtt服务器软件-CSDN博客 特此致谢&#xff01; 在前一篇文章中&#xff0c;笔者通过MQTTX实现了通过图形界面环境收发MQTT消息。但是…

SPARC VScode EIDE GDB 使用配置

前言 搞了多年的SPARC 最近接触了VSCODE插件感觉好用。想想看不是能方便调试和编译SPARC&#xff0c;决定使用开源的SPARC仿真环境和编译器来试试。感觉的却不错&#xff0c;借此献给使用SPARC的朋友们。安装 1.找微软官方的下载VSCODE. 2.电机左边的方块形状的图标&#xff0…

由于找不到msvcr110.dll,无法继续执行代码的解决方法

在日常使用计算机的过程中&#xff0c;可能会遇到系统提示缺少msvcr110.dll文件的情况&#xff0c;这一问题往往导致某些应用程序无法正常运行。幸运的是&#xff0c;有多种方法可以有效应对这一困境&#xff0c;帮助您的计算机恢复顺畅运作。以下是解决计算机丢失msvcr110.dll…

【游戏行业】2024年电子游戏分类,国内游戏产业报告,发展趋势

文章目录 一、电子游戏分类1、传统游戏分类2、混合手游分类3、二次元、开放设计、调查问卷 二、游戏产业报告1、游戏产业数据2、游戏公司名单&#xff08;独角兽&#xff09;3、营收与利润&#xff08;对比互联网、国企&#xff09; 三、发展趋势1、游戏行业上下游2、游戏行业趋…

正点原子[第二期]Linux之ARM(MX6U)裸机篇学习笔记-12-蜂鸣器

前言&#xff1a; 本文是根据哔哩哔哩网站上“正点原子[第二期]Linux之ARM&#xff08;MX6U&#xff09;裸机篇”视频的学习笔记&#xff0c;在这里会记录下正点原子 I.MX6ULL 开发板的配套视频教程所作的实验和学习笔记内容。本文大量引用了正点原子教学视频和链接中的内容。…

PX4二次开发快速入门(三):自定义串口驱动

文章目录 前言 前言 软件&#xff1a;PX4 1.14.0稳定版 硬件&#xff1a;纳雷NRA12&#xff0c;pixhawk4 仿照原生固件tfmini的驱动进行编写 源码地址&#xff1a; https://gitee.com/Mbot_admin/px4-1.14.0-csdn 修改 src/drivers/distance_sensor/CMakeLists.txt 添加 add…

01-MySQL 基础篇笔记

一、MySQL 概述 1.1 数据库相关概念 数据库&#xff1a;&#xff08;DB&#xff1a;DataBase&#xff09; 存储数据的仓库&#xff0c;数据是有组织的进行存储 数据库管理系统&#xff1a;&#xff08;DBMS&#xff1a;DataBase Management System&#xff09; 操作和管理数…

IoTDB 入门教程 基础篇⑨——TsFile导入导出工具

文章目录 一、前文二、准备2.1 准备导出服务器2.2 准备导入服务器 三、导出3.1 导出命令3.2 执行命令3.3 tsfile文件 四、导入4.1 上传tsfile文件4.2 导入命令4.3 执行命令 五、查询六、参考 一、前文 IoTDB入门教程——导读 数据库备份与迁移是数据库运维中的核心任务&#xf…

最小费用流相位解包裹

% test_cunwrap.m % % Matlab script to test Costantinis unwrapping % Author: Bruno Luong <brunoluong@yahoo.com> % History: % Orginal: 27-Aug-2009clear all; close all; clc; I1=double(imread(E:\zhenlmailcom-E8E745\华为家庭存储\.public_files\博士阶段\小…

[stm32-1]LED闪烁LED流水灯蜂鸣器

1、LED闪烁&LED流水灯&蜂鸣器 1.使用RCC开启GPIO时钟 2.使用GPIO_Init函数初始化GPIO 3.使用输入或输出函数控制GPIO口 RCC常用的3个库函数&#xff1a; void RCC_AHBPeriphClockCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState); void RCC_APB2PeriphClockC…

C++中的reverse_iterator迭代器结构设计

目录 reverse_iterator迭代器结构设计 reverse_iterator迭代器基本结构设计 operator*()函数 operator()函数 operator->()函数 operator!()函数 rbegin()函数 rend()函数 operator--()函数 operator()函数 测试代码 const_reverse_iterator迭代器设计 reverse…

【数据结构】第四讲:双向链表

目录 一、链表的分类 二、双向链表的结构及实现 1.带头双向链表的结构 2.创建节点 3.初始化 4.尾插 5.打印 6.头插 7.尾删 8.头删 9.在pos位置之后插入数据 10.删除pos节点 11.查找 12.销毁 个人主页&#xff1a;深情秋刀鱼-CSDN博客 数据结构专栏&#xff1a;数…

java基于云计算的SaaS医院his信息系统源码 HIS云平台源码

目录 云HIS功能模块 1、预约挂号&#xff1a; 2、药库管理&#xff1a; 3、门诊医生站&#xff1a; 4、门诊费用&#xff1a; 5、药房管理&#xff1a; 6、治疗室&#xff08;门诊护士工作站&#xff09;&#xff1a; 7、统计分析&#xff1a; 8、财务管理&#xff1a;…