背景是有个sdk项目,最近我需要接入它使用。在接入的时候遇到了一些问题,所以有本文。
背景问题
sdk项目依赖了三个子模块,大约是这样的:
dependencies{implementation(project(":module-A"))implementation(project(":module-B"))implementation(project(":module-C"))}我加了点代码publish到我新创建的maven服务。
- 编译报错依赖 module-A、B、C找不到, 手动忽略了报错。
- 运行时报错,这时候我发现module-A、B、C
这时候我发现这三个项目都不会发布到maven上。这几个项目我都不熟悉,特别是他们都定义了多个productFlavors。
这种情况怎么简单合成一个repo给我自己使用呢?
以前的经验
android多aar合并
android{ buildTypes{ release { minifyEnabled true } } }大约就是自己写脚本合并,使用python,和项目无关,不用收到agp版本的制约。
但是这个写了脚本我后面也不一定会用到,我就在想有没有其他的方式。
fat-aar-:
https://github.com/aasitnikov/fat-aar-android
kezong/fat-aar-android 这个没维护了,只是支持到AGP3.0.找到一些它的issue,发现有一个下游的分支还在更新。
aasitnikov/fat-aar-android 下游这个支持到 agp 8.13
我试了一下,发现 存在问题:
- embed 的关键词没有找到
- 项目中使用kotlin-dsl,不知道是不是我哪里设置不对,用的时候有一些报错
fusedlibrary
fused-library
这个也存在一些问题:
- viewBinding = true 不支持
- minifyEnabled true会有报错,比较奇怪
不过总体是可以用的,可以这样使用:
- 创建一个新的module,这个module下只有一个
build.gradle.kts的文件 - 在 build.gradle.kts 这里依赖其他的module,差不多是这样
dependencies{include(project(":module-A"))include(project(":module-B"))include(project(":module-C"))}step by step的说明见这里 add-fused-library-module
发布,直接publish就好
./gradlew clean :myFusedLibrary:publishstep by step细节
- Enable fused library support by adding
android.experimental.fusedLibrarySupport=trueto thegradle.propertiesfile. - Append
include(":myFusedLibrary")to thesettings.gradle.ktsfile. - Add
android-fusedlibrary = { id = "com.android.fused-library", version.ref = "agp" }under the[plugins]section in thegradle/libs.versions.tomlfile. - Add
alias(libs.plugins.android.fusedlibrary) apply falsein the plugins block in the top levelbuild.gradle.ktsfile. - To create the
myFusedLibrarymodule, create a new directory called myFusedLibrary (right-click ‘My Application’ > New > Directory). - Create a
build.gradle.ktsfile in the myFusedLibrary module (right-click the myFusedLibrary module > New > File). - Paste the following into the
myFusedLibrary/build.gradle.ktsfile:
plugins{alias(libs.plugins.android.fusedlibrary)`maven-publish`}valbuildTime=java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))androidFusedLibrary{namespace="org.yeshen.fusedlibrary"minSdk=21}dependencies{include(project(":module-A"))include(project(":module-B"))include(project(":module-C"))}publishing{publications{register<MavenPublication>("release"){groupId="org.yeshen.fusedlibrary"artifactId="awesome"version="1.0.$buildTime"from(components["fusedLibraryComponent"])}}repositories{maven{url=uri("file://${rootDir}/../yeshen/file_release")name="Local"}}}参考
- fused-library
- aasitnikov/fat-aar-android
- android多aar合并
本系列其他文章
- 多个project合成一个aar发布
- android多aar合并
- 多AAR合并之二Merge multiple jar/aar maven url into one