kezong / fat-aar-android

A gradle plugin that merge dependencies into the final aar file works with AGP 3.+
MIT License
3.08k stars 607 forks source link

一种安全的替换 fat-aar-android 插件的方法 #416

Open kapaseker opened 8 months ago

kapaseker commented 8 months ago

fat-aar-android不再更新带来的问题

目前遇到两个比较麻烦的点:

解决方案

完全依赖Gradle进行多Module打包:

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

// 定义工程的资源目录
def source_path = '/src/main/java' //源码
def aidl_path = '/src/main/aidl' //aidl
def res_path = '/src/main/res' // res
def assets_path = '/src/main/assets' // assets
def jni_path = '/src/main/jniLibs' // jni so

// 定义需要打包的module目录
def module_list = [
        project("1xxxx"),
        project("2xxxx"),
        project("3xxxx"),
        project("4xxxx"),
]

android {
    // 省略其他定义

    // 定义maven-publish需要的release
    publishing {
        singleVariant('release') {
           //需要源码
            withSourcesJar()
           //需要Javadoc
            withJavadocJar()
        }
    }

   //定义所有的资源目录
    sourceSets {
        def source_dirs = []
        def aidl_dirs = []
        def res_dirs = []
        def assets_dirs = []
        def jni_dirs = []
        module_list.forEach {
            source_dirs.add(it.getProjectDir().absolutePath + source_path)
            aidl_dirs.add(it.getProjectDir().absolutePath + aidl_path)
            res_dirs.add(it.getProjectDir().absolutePath + res_path)
            assets_dirs.add(it.getProjectDir().absolutePath + assets_path)
            jni_dirs.add(it.getProjectDir().absolutePath + jni_path)
        }

        main {
            java.srcDirs = source_dirs
            aidl.srcDirs = aidl_dirs
            res.srcDirs = res_dirs
            assets.srcDirs = assets_dirs
            jniLibs.srcDirs = jni_dirs
        }
    }
}

publishing {
    publications {
        release(MavenPublication) {

            groupId = 'xxx'
            artifactId = 'xxx'
            version = "xxx"

            afterEvaluate {
                from components.release
            }
        }
    }
    repositories {
        maven {
           //省略maven定义
        }
    }
}

dependencies {
    //如果工程有其他依赖,在这里使用 compileOnly 进行声明
    compileOnly xxx
}
HamzaOban commented 8 months ago

Did you find a solution?

zuilintan commented 8 months ago

Thank you, I think I can try it

zuilintan commented 8 months ago

Unfortunately, it has a problem. The Java file generated by the sub -Module Aidl file seems to produce two copies. It is prompted to repeat.

可惜, 它存在一个问题, 子Module的AIDL文件生成的java文件, 似乎会产出两份, 提示类重复.

kapaseker commented 8 months ago

a

if it works, then it is not a problem. just a warning.

kapaseker commented 8 months ago

Did you find a solution? it works.

dyguests commented 6 months ago

先Mark,有空研究下能不能用。

有办法把依赖的三方库也合并到aar中吗?

kapaseker commented 6 months ago

~先Mark,有空研究下能不能用。~

有办法把依赖的三方库也合并到aar中吗?

@dyguests 这个方法不行,只能包含源码

weikeet commented 6 months ago

引用的模块, 只能被一个模块引用