Android Gradle构建常见问题

ButterKnife attribute value must be constant

在Project级的build.gradle中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
//注意版本,务必使用8.4.0版本
classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
}
}

在Module级的build.gradle中

1
2
3
4
5
6
7
8
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'

dependencies {
//ButterKnife依赖
api 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}

Execution failed for task ‘:app:compileDebugJavaWithJavac’

参考:https://stackoverflow.com/questions/48071618/execution-failed-for-task-appcompiledebugjavawithjavac-android-studio-3-1-up

如果build窗口没有详细错误信息,则单独执行gradle构建任务:Gradle窗口 -> Module -> Tasks -> build -> assembleDebug,此时会显示更详细的错误信息

Default interface methods are only supported starting with Android N (–min-api 24)

参考:https://stackoverflow.com/questions/49512629/android-studio-error-default-interface-methods-are-only-supported-starting-with

在Module级的build.gradle中

1
2
3
4
5
6
7
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

Program type already present: android.support.v13.view.DragAndDropPermissionsCompat

在Module级的build.gradle中

1
2
3
4
5
dependencies {
configurations {
all*.exclude group: 'com.android.support', module: 'support-v13'
}
}

Gradle: 错误: 编码GBK的不可映射字符

在Module级的build.gradle中

1
2
3
4
5
6
7
8
apply plugin: 'java'

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"
1
2
3
4
5
apply plugin: 'android'

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

编译apk失败提示:无法访问ActivityCompatApi23

1、检查是否重复引用v4包
2、检查项目引用的v4包与第三方框架依赖的v4包版本是否一致
3、Clean Project

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :