Android Gradle构建常见问题

ButterKnife attribute value must be constant

在Project级的build.gradle中

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中

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中

android {
    ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

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

在Module级的build.gradle中

dependencies {
    configurations {
        all*.exclude group: 'com.android.support', module: 'support-v13'
    }
}

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

在Module级的build.gradle中

apply plugin: 'java'

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

sourceCompatibility = "1.8"
targetCompatibility = "1.8"
apply plugin: 'android'

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

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

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

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/11/common-issues-with-building-android-gradle/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Android Gradle构建常见问题
ButterKnife attribute value must be constant 在Project级的build.gradle中 buildscript { repositories { google() jcenter() ……
<<上一篇
下一篇>>
文章目录
关闭
目 录