kotlin android library 发布至jitpack问题及解决方式记载

在使用较新版本gradle(笔者版本为7.0.2)的android library项目中,想要成功通过jitpack编译发布会遇到一系列问题,部分问题在这篇文章

gradle7.0.2如何发布jitpack开源项目_我想月薪过万的博客-CSDN博客​​​​​​

中已有了正确的处理方法,但还是遇到其中未记载到的问题。其中比较令人困惑的问题是这个

https://jitpack.io/com/github/EnthuDai/SimpleChart-Kotlin/1.0.5/build.log

 可以看到里面

BUILD SUCCESSFUL in 2m 30s
134 actionable tasks: 131 executed, 3 up-to-date
No issues found.
Build tool exit code: 0
Looking for artifacts...
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Looking for pom.xml in build directory and ~/.m2
2022-01-12T08:49:49.48117059Z
Exit code: 0

ERROR: No build artifacts found

 成功build但是

ERROR: No build artifacts found

 对于这个问题,目前网上较多(但未必正确)的解决方案是在library的build.gradle中添加

publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId = 'org.gradle.sample'
            artifactId = 'library'
            version = '1.1'

            from components.java
        }
    }
}

 或是类似的代码段

该方法的出处在

https://sami.eljabali.org/how-to-publish-a-kotlin-library-to-jitpack/

但该方法在我的项目gradle的sysc阶段,就会报错,无法正常编译

经过多番研究(科学上网搜索),最终找到真正的解决方法:

plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'maven-publish'
}

...
android {
    afterEvaluate {
        publishing {
            publications {
                release(MavenPublication) {
                    from components.release
                }
            }
        }
    }
...

该方法出自jitpack项目的issues中 

https://github.com/jitpack/jitpack.io/issues/3814

至此终于成功在jitpack上成功编译并发布!

但当引用此编译的项目源时,仍然遇到问题:在jitpack官网提供的依赖引用方式:

To get a Git project into your build:

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

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

Step 2. Add the dependency

	dependencies {
	        implementation 'com.github.EnthuDai:SimpleChart-Kotlin:Tag'
	}

发现在新版的gradle中,需要将

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

写在 settings.gradle 中才能正确引用,即:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
        maven { url 'https://jitpack.io' }
    }
}

至此,终于成功完成一个 kotlin android library的发布和使用。

完整的示例大家可参考我的开源项目:

https://github.com/EnthuDai/SimpleChart-Kotlin.git

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值