Android Studio常见编译错误

一、常见错误

1、Android编译报错 > Could not find :xxx Required by: project :app > project :xxx

项目有2个 Module:
一个app,
一个xxxModule

在xxxModule中使用了aar库,且在build.gradle中按如下配置

repositories {
    flatDir {
        dirs 'libs'
    }
}
dependencies {
  implementation(name: 'xxx-sdk', ext: 'aar')
}

解决问题

在项目 build.gradle中添加如下代码

allprojects {
    repositories {
        google()
        jcenter()

        flatDir {
            //project中xxx即为使用aar的那个module的名称
            dirs project(':xxx').file('libs')
        }
    }
}

2、resource android:attr/lStar not found.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':ip_demo:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed
     C:\Users\GW00306182\.gradle\caches\transforms-2\files-2.1\49a781212cc489a8f2a111cf264d4c2a\core-1.7.0\res\values\values.xml:105:5-114:25: AAPT: error: resource android:attr/lStar not found.

排查发现引入了 androidx.core:core:1.7.0
强制项目使用1.6.0 也不好使 1.5以下也不好使

configurations.all {
    resolutionStrategy {
        force 'androidx.core:core:1.6.0'
    }
}

最终解决方案两种:
1、将compileSdkVersion 改为31
2、activity:activity、fragment:fragment和appcompat:appcompat冲突,注释掉activity和fragment

androidx.activity:activity-ktx:1.4.0
androidx.fragment:fragment-ktx:1.3.0
androidx.appcompat:appcompat:1.3.1

你可能感兴趣的:(Android Studio常见编译错误)