特别注意
如果主项目和要导入的项目其中已经有已升级androidX 建议全部升级androidx 不然很多到会让你放弃重来
1 选择import Module:
2,选择要导入的module,如果此module还依赖了其他module会在下面图片里一起显示,默认勾选
3 修改导入的module的build.gradle文件内容(如果它之前在项目里是主module的话)
-
apply plugin: ‘com.android.application’
改成
apply plugin: ‘com.android.library’ -
删除defaultConfig或productFlavors里的
applicationId
-
删除 AndroidMenifest.xml里定义的包含android.intent.action.MAIN的 intent-filter(注意不是删除整个activity标签)
4 修改导入后的项目中主module也就是app里的文件:
- AndroidMenifest.xml兼容android:allowBackup,android:icon
增加 tools:replace=“android:allowBackup,android:icon”
<application
...
tools:replace="android:allowBackup,android:icon">
- 编译时如果有AndroidMenifest报错:
找到左边报错的erro根据提示点击修改意见会自动合并.
5 当导入的modle未被系统识别到:
就是module旁边没有下图图案
- 检查这个文件 如果include 里没有这个module名称 手动添加即可
- 检查 Project Structure 配置sdkLocation 特别NDK路径 (如果用到的话)
6 其他报错
- Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列的字节 2 无效。
Editor->File Encodings 改成相同编码试试
- Error:error: resource previously defined here. AAPT2 error: check logs for details
根据报错信息查找 即使报错信息的内容是自动生成的文件
去查找 例如 重命名textColor,名称不与系统的textColor一样即可。
<declare-styleable name="xxx">
<attr name="不能和系统属性关键字同名" format="xxx"/>
</declare-styleable>