Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kapaseker opened this issue Nov 1, 2023 · 8 comments
Open

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

kapaseker opened this issue Nov 1, 2023 · 8 comments

Comments

@kapaseker
Copy link

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

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

  • 不再更新,无法支持gradle8.0。(该问题在issue区是有解决方案的)
  • 无法导出Kotlin的顶层定义(包括扩展,函数,常量定义)。

解决方案

完全依赖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
Copy link

Did you find a solution?

@zuilintan
Copy link

Thank you, I think I can try it

@zuilintan
Copy link

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
Copy link
Author

a

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

@kapaseker
Copy link
Author

Did you find a solution?
it works.

@dyguests
Copy link

dyguests commented Dec 13, 2023

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

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

@kapaseker
Copy link
Author

kapaseker commented Dec 21, 2023

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

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

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

@weikeet
Copy link

weikeet commented Dec 26, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants