aar包有着越来越强的应用性,jar包,so文件都可以把所在moudle变为依赖库进而打进aar中,供其他app调用
1打成aar的方法
module的build.gradle文件apply plugin: 'com.android.application’改为apply plugin: ‘com.android.library’ applicationId "com.wintec.myapplication"去掉
把不需要的资源去掉:比如Activity,drawable文件夹等
执行make moudle之后在build–outputs–aar文件下找到所需要的aar文件
注意事项:
1)清单文件可以删除到这个程度
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wintec.weigh">
</manifest>
否则引入新的app中运行会报错:default Activity not found
2)根据报错信息修改,比如我的项目中把application中的xutils代码注释掉了
2在新的app中的清单文件,在application标签中增加tools:replace=“android:icon”
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:icon"
>
否则会报icon重复的异常
3新的app如何使用aar?
1)把aar文件拷贝到libs中
2)moudle下的build.gradle中的dependencies下添加
dependencies {
api fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
}
4如果出现apk跑起来,资源调用不到的问题(代码爆红),重启一下android studio即可