Gradle 由于 Android 上的 lint 类路径错误,构建失败
Gradle build fails due to lint classpath error on Android
我有一个 Android 应用程序,当我 运行 以下命令时,它的构建失败:
./gradlew clean build -Pbuild=dev --stacktrace
这是我收到的错误:
> Task :app:lint FAILED
FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':app:lint'.
> No value has been specified for property 'lintClassPath'.
应用模块build.gradle文件:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'
apply plugin: "androidx.navigation.safeargs"
// For Epoxy
kapt {
correctErrorTypes = true
}
android {
kotlinOptions {
jvmTarget = '1.6'
}
compileSdkVersion 28
defaultConfig {
applicationId "..."
minSdkVersion 21
targetSdkVersion 28
versionCode 8
versionName "0.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
debug {
if (project.hasProperty('ApiKey')) {
buildConfigField('String', 'API_KEY', ApiKey)
} else {
buildConfigField('String', 'API_KEY', "\"mock-key\"")
}
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if (project.hasProperty('ApiKey')) {
buildConfigField('String', 'API_KEY', ApiKey)
} else {
buildConfigField('String', 'API_KEY', "\"mock-key\"")
}
}
}
def build_param = "${build}"
if (build_param != "dev") {
//exclude production build
android.variantFilter { variant ->
if (variant.buildType.name == 'dev') {
variant.setIgnore(true)
}
}
} else {
//exclude all except production build
android.variantFilter { variant ->
if (variant.buildType.name != 'dev') {
variant.setIgnore(true)
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
androidExtensions {
experimental = true
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
// Android
def lifecycle_version = "2.0.0"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation 'com.google.android.material:material:1.0.0'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation 'androidx.core:core-ktx:1.0.1'
implementation 'androidx.preference:preference:1.0.0'
implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
def room_version = "2.1.0-alpha04"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-rxjava2:$room_version"
kapt "androidx.room:room-compiler:$room_version"
def nav_version = "1.0.0-rc02"
implementation "android.arch.navigation:navigation-fragment-ktx:$nav_version"
implementation "android.arch.navigation:navigation-ui-ktx:$nav_version"
// Networking
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
implementation 'com.squareup.okhttp3:okhttp:3.13.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.13.1'
implementation 'com.squareup.retrofit2:converter-moshi:2.4.0'
implementation 'com.squareup.moshi:moshi-adapters:1.8.0'
// DI
def koin_version = "1.0.2"
implementation "org.koin:koin-android:$koin_version"
implementation "org.koin:koin-androidx-scope:$koin_version"
implementation "org.koin:koin-androidx-viewmodel:$koin_version"
// Rx
implementation 'io.reactivex.rxjava2:rxjava:2.2.7'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0'
implementation 'com.jakewharton.rxbinding2:rxbinding:2.2.0'
implementation 'com.jakewharton.rxrelay2:rxrelay:2.1.0'
// Image Loading
implementation 'com.github.bumptech.glide:glide:4.8.0'
kapt 'com.github.bumptech.glide:compiler:4.8.0'
// Tests
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.24.5'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
// UI
implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:9.0.1'
implementation 'com.airbnb.android:epoxy:3.2.0'
kapt 'com.airbnb.android:epoxy-processor:3.2.0'
implementation 'com.github.VladimirWrites:Lemniscate:1.4.4'
// Firebase
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
}
apply plugin: 'com.google.gms.google-services'
项目级别build.gradle文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.21'
repositories {
jcenter()
maven {
url 'https://maven.fabric.io/public'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.2.0'
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-rc02"
classpath 'io.fabric.tools:gradle:1.27.0'
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
}
maven {
url 'https://jitpack.io'
}
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我不确定如何解决这个问题。降级 Android Gradle 插件并不能解决问题,Github 或 Whosebug 上也没有与此相关的问题。
有人知道如何解决这个问题吗?
我明白问题出在哪里了。我使用构建参数 'dev' (Pbuild=dev
) 来确保 CI(Travis,在这种情况下)使用我的 google-services.json
文件的模拟版本放置在 app/src/dev
文件夹。但是,我忘记在模块的 build.gradle 文件中配置 'dev' 构建变体。
解决方案是在所有模块中添加 dev
构建类型,如下所示:
build.gradle
android {
...
buildTypes {
release {
...
}
debug {
...
}
dev {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
请注意,您必须对项目中的所有模块执行此操作。
在我的例子中,触发此错误是因为 ANDROID_HOME
未设置环境变量
我必须先接受许可。奇怪的错误。
在 macOS 上:
yes | sudo ~/Library/Android/sdk/tools/bin/sdkmanager --licenses
对于其他平台,请参阅
导致此问题的原因是Gradle 找不到Android SDK。有几种修复方法:
定义ANDROID_HOME
环境变量
ANDROID_HOME=your/path/to/android/sdk; export ANDROID_HOME
或将 sdk.dir
添加到文件 local.properties
,例如在我的 Linux 计算机上
sdk.dir=/home/sdeng/Android/Sdk
如果您已经定义了 ANDROID_HOME
或 sdk.dir
,它仍然会发生。您的 Android SDK 或 Gradle 守护程序的特定版本可能有问题。尝试杀死所有Gradle进程,重新下载特定版本的Android SDK。
或者你可以查看$ANDROID_HOME/platforms/android-28
目录下的SDK,其中28是build.gradle
中定义的compileSdkVersion
即使设置了 ANDROID_HOME
,正如其他人建议的那样,请确保该目录确实可用。我在 chroot 环境中构建,并忽略了编辑我的 chroot.sh 脚本来说明我较新笔记本电脑的目录布局。结果,link 到我的 Windows 分区上的目录的 $HOME/Downloads
是死的 link,并且找不到 Android SDK。
我有一个 Android 应用程序,当我 运行 以下命令时,它的构建失败:
./gradlew clean build -Pbuild=dev --stacktrace
这是我收到的错误:
> Task :app:lint FAILED
FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':app:lint'.
> No value has been specified for property 'lintClassPath'.
应用模块build.gradle文件:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'
apply plugin: "androidx.navigation.safeargs"
// For Epoxy
kapt {
correctErrorTypes = true
}
android {
kotlinOptions {
jvmTarget = '1.6'
}
compileSdkVersion 28
defaultConfig {
applicationId "..."
minSdkVersion 21
targetSdkVersion 28
versionCode 8
versionName "0.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
debug {
if (project.hasProperty('ApiKey')) {
buildConfigField('String', 'API_KEY', ApiKey)
} else {
buildConfigField('String', 'API_KEY', "\"mock-key\"")
}
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if (project.hasProperty('ApiKey')) {
buildConfigField('String', 'API_KEY', ApiKey)
} else {
buildConfigField('String', 'API_KEY', "\"mock-key\"")
}
}
}
def build_param = "${build}"
if (build_param != "dev") {
//exclude production build
android.variantFilter { variant ->
if (variant.buildType.name == 'dev') {
variant.setIgnore(true)
}
}
} else {
//exclude all except production build
android.variantFilter { variant ->
if (variant.buildType.name != 'dev') {
variant.setIgnore(true)
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
androidExtensions {
experimental = true
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
// Android
def lifecycle_version = "2.0.0"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation 'com.google.android.material:material:1.0.0'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation 'androidx.core:core-ktx:1.0.1'
implementation 'androidx.preference:preference:1.0.0'
implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
def room_version = "2.1.0-alpha04"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-rxjava2:$room_version"
kapt "androidx.room:room-compiler:$room_version"
def nav_version = "1.0.0-rc02"
implementation "android.arch.navigation:navigation-fragment-ktx:$nav_version"
implementation "android.arch.navigation:navigation-ui-ktx:$nav_version"
// Networking
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
implementation 'com.squareup.okhttp3:okhttp:3.13.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.13.1'
implementation 'com.squareup.retrofit2:converter-moshi:2.4.0'
implementation 'com.squareup.moshi:moshi-adapters:1.8.0'
// DI
def koin_version = "1.0.2"
implementation "org.koin:koin-android:$koin_version"
implementation "org.koin:koin-androidx-scope:$koin_version"
implementation "org.koin:koin-androidx-viewmodel:$koin_version"
// Rx
implementation 'io.reactivex.rxjava2:rxjava:2.2.7'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0'
implementation 'com.jakewharton.rxbinding2:rxbinding:2.2.0'
implementation 'com.jakewharton.rxrelay2:rxrelay:2.1.0'
// Image Loading
implementation 'com.github.bumptech.glide:glide:4.8.0'
kapt 'com.github.bumptech.glide:compiler:4.8.0'
// Tests
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.24.5'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
// UI
implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:9.0.1'
implementation 'com.airbnb.android:epoxy:3.2.0'
kapt 'com.airbnb.android:epoxy-processor:3.2.0'
implementation 'com.github.VladimirWrites:Lemniscate:1.4.4'
// Firebase
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
}
apply plugin: 'com.google.gms.google-services'
项目级别build.gradle文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.21'
repositories {
jcenter()
maven {
url 'https://maven.fabric.io/public'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.2.0'
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-rc02"
classpath 'io.fabric.tools:gradle:1.27.0'
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
}
maven {
url 'https://jitpack.io'
}
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我不确定如何解决这个问题。降级 Android Gradle 插件并不能解决问题,Github 或 Whosebug 上也没有与此相关的问题。
有人知道如何解决这个问题吗?
我明白问题出在哪里了。我使用构建参数 'dev' (Pbuild=dev
) 来确保 CI(Travis,在这种情况下)使用我的 google-services.json
文件的模拟版本放置在 app/src/dev
文件夹。但是,我忘记在模块的 build.gradle 文件中配置 'dev' 构建变体。
解决方案是在所有模块中添加 dev
构建类型,如下所示:
build.gradle
android {
...
buildTypes {
release {
...
}
debug {
...
}
dev {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
请注意,您必须对项目中的所有模块执行此操作。
在我的例子中,触发此错误是因为 ANDROID_HOME
未设置环境变量
我必须先接受许可。奇怪的错误。
在 macOS 上:
yes | sudo ~/Library/Android/sdk/tools/bin/sdkmanager --licenses
对于其他平台,请参阅
导致此问题的原因是Gradle 找不到Android SDK。有几种修复方法:
定义ANDROID_HOME
环境变量
ANDROID_HOME=your/path/to/android/sdk; export ANDROID_HOME
或将 sdk.dir
添加到文件 local.properties
,例如在我的 Linux 计算机上
sdk.dir=/home/sdeng/Android/Sdk
如果您已经定义了 ANDROID_HOME
或 sdk.dir
,它仍然会发生。您的 Android SDK 或 Gradle 守护程序的特定版本可能有问题。尝试杀死所有Gradle进程,重新下载特定版本的Android SDK。
或者你可以查看$ANDROID_HOME/platforms/android-28
目录下的SDK,其中28是build.gradle
compileSdkVersion
即使设置了 ANDROID_HOME
,正如其他人建议的那样,请确保该目录确实可用。我在 chroot 环境中构建,并忽略了编辑我的 chroot.sh 脚本来说明我较新笔记本电脑的目录布局。结果,link 到我的 Windows 分区上的目录的 $HOME/Downloads
是死的 link,并且找不到 Android SDK。