android 导入别的项目或module作为library 步骤和注意点

特别注意
如果主项目和要导入的项目其中已经有已升级androidX 建议全部升级androidx 不然很多到会让你放弃重来

1 选择import Module:

在这里插入图片描述

2,选择要导入的module,如果此module还依赖了其他module会在下面图片里一起显示,默认勾选

在这里插入图片描述

3 修改导入的module的build.gradle文件内容(如果它之前在项目里是主module的话)

  1. apply plugin: ‘com.android.application’
    改成
    apply plugin: ‘com.android.library’

  2. 删除defaultConfig或productFlavors里的
    applicationId
    在这里插入图片描述

  3. 删除 AndroidMenifest.xml里定义的包含android.intent.action.MAIN的 intent-filter(注意不是删除整个activity标签)
    在这里插入图片描述

4 修改导入后的项目中主module也就是app里的文件:

  1. AndroidMenifest.xml兼容android:allowBackup,android:icon
    增加 tools:replace=“android:allowBackup,android:icon”
<application
 ...
 tools:replace="android:allowBackup,android:icon">
  1. 编译时如果有AndroidMenifest报错:
    在这里插入图片描述
    找到左边报错的erro根据提示点击修改意见会自动合并.

5 当导入的modle未被系统识别到:

就是module旁边没有下图图案
在这里插入图片描述

  1. 检查这个文件 如果include 里没有这个module名称 手动添加即可
    在这里插入图片描述
  2. 检查 Project Structure 配置sdkLocation 特别NDK路径 (如果用到的话)
    在这里插入图片描述

6 其他报错

  1. Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列的字节 2 无效。

Editor->File Encodings 改成相同编码试试

  1. Error:error: resource previously defined here. AAPT2 error: check logs for details
    根据报错信息查找 即使报错信息的内容是自动生成的文件
    去查找 例如 重命名textColor,名称不与系统的textColor一样即可。
    在这里插入图片描述
<declare-styleable name="xxx">
        <attr name="不能和系统属性关键字同名" format="xxx"/>
</declare-styleable>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值