将module模块变成aar文件

在项目开发中,我们经常会使用jar或者aar文件作为第三方库引入工程中,jar和aar的区别是什么呢?

aar:包含class文件和资源文件名,是android的专属jar
jar:仅仅包含class和清单文件,不支持资源文件

将mudle变成aar的步骤如下:

第一步:创建完module模块以后,写完功能逻辑,使用Build -> Make Module "common"

第二步:我们就可以到moudle模块中的build/outputs/aar/ 文件下,看到生成的aar文件了。

第三步:我们就可以将common.aar文件复制到项目的libs包下

第四步:在gradle中就可以引用aar文件了 

repositories {
    flatDir {
        dirs 'libs'  //使用libs包文件
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:25.4.0'
    implementation(name: 'common-debug', ext: 'aar') //添加指定的aar文件
}

你可能感兴趣的:(android)