当前位置: 首页 > 知识库问答 >
问题:

不能用Android Studio 3.0+DataBinding+Kotlin构建项目

康赞
2023-03-14
kapt 'com.android.databinding:compiler:3.0.0'

“Android处理器”依赖项不会被识别为kapt注释处理器。请将这些工件的配置名更改为'kapt':'com.android.DataBinding:Compiler:3.0.0'。

我试过但没有用:

   kapt {
    generateStubs = true
}

在local.properties中:kotlin.incremental=false

另一个SO解决方案也无济于事:

kapt ('com.android.databinding:compiler:3.0.0'){
        force = true
    }

我的建筑。Gradle

 apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'
apply plugin: 'blockcanaryex'
apply plugin: 'kotlin-kapt'
apply plugin: 'newrelic'
apply plugin: 'kotlin-android-extensions'

def props = new Properties()
file("newrelic.properties").withInputStream { props.load(it) }

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def stdout = new ByteArrayOutputStream()
            exec {
                commandLine "git", "symbolic-ref", "--short", "HEAD"
                standardOutput = stdout
            }
            def branch = stdout.toString().trim()
            branch = "branch.$branch"

            if (project.hasProperty("buildNumber")) {
                def buildNumber = project.property("buildNumber")
                output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace(".apk", "-" + branch + "-" + versionName + "." + versionCode + "." + buildNumber + ".apk"))
            } else {
                output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace(".apk", "-" + branch + "-" + versionName + "." + versionCode + ".apk"))
            }
        }
    }

    def version = "4.15"

    defaultConfig {
        buildConfigField "String", "TOKEN", "\"" + props.getProperty("token") + "\""
        applicationId "xxx"
        minSdkVersion 19
        targetSdkVersion 26
        versionName version

        versionCode 260

        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
    }



    signingConfigs {
        release {
            storeFile file("xxx")
            storePassword "xxx"
            keyAlias "xxx"
            keyPassword "xxx"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            signingConfig signingConfigs.release
        }

        debug {
            versionNameSuffix ".debug"
        }
    }
    flavorDimensions "prod","stag"

    productFlavors {



        production {
            dimension "prod"
        }

        staging {
            dimension "stag"
            applicationId "app.id"
            versionName(version + ".staging")
        }

    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude '.readme'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    dataBinding {
        enabled = true
    }
}


repositories {
    jcenter()
    maven { url "https://jitpack.io" }
    maven { url 'https://bitbucket.org/gryphteam/maven/raw/release' }
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
}


def supportVersion = "26.1.0"
def playServicesVersion = "11.6.0"
def retrofitVersion = "2.3.0"

dependencies {


    implementation 'com.jakewharton:butterknife:6.1.0'
    implementation('de.keyboardsurfer.android.widget:crouton:1.8.5@aar') {
        exclude group: 'com.google.android', module: 'support-v4'
    }
    implementation 'com.google.dagger:dagger:2.10'
    kapt 'com.google.dagger:dagger-compiler:2.10'
    kapt 'com.android.databinding:compiler:3.0.0'


    implementation 'de.greenrobot:eventbus:2.4.0'
    implementation 'com.mcxiaoke.volley:library:1.0.19'

    implementation 'com.google.code.gson:gson:2.8.0'
    implementation "com.google.android.gms:play-services-places:$playServicesVersion"
    implementation "com.google.android.gms:play-services-plus:$playServicesVersion"
    implementation "com.google.android.gms:play-services-analytics:$playServicesVersion"
    implementation "com.google.android.gms:play-services-auth:$playServicesVersion"
    implementation "com.google.android.gms:play-services-gcm:$playServicesVersion"
    implementation "com.google.android.gms:play-services-ads:$playServicesVersion"

    implementation "com.android.support:appcompat-v7:$supportVersion"
    implementation "com.android.support:support-v13:$supportVersion"
    implementation "com.android.support:recyclerview-v7:$supportVersion"
    implementation "com.android.support:design:$supportVersion"
    implementation "com.android.support:support-annotations:$supportVersion"
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:multidex:1.0.2'

    implementation 'commons-io:commons-io:2.4'
    implementation 'org.apache.commons:commons-lang3:3.1'
    implementation files('libs/comscore.jar')
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2'
    implementation 'com.github.deano2390:MaterialShowcaseView:1.0.5'
    implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
    implementation 'com.google.ads.mediation:facebook:4.26.1.0'
    implementation 'com.facebook.android:audience-network-sdk:4.26.1'
    implementation 'org.jboss.netty:netty:3.2.10.Final'

    //Testing
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:1.10.19'
    androidTestImplementation 'com.android.support:multidex:1.0.2'
    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test.espresso:espresso-web:3.0.1'
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2') {
        exclude group: 'com.android.support', module: 'support-annotations:22.2.1'
    }
    androidTestImplementation('com.android.support.test:runner:0.3') {
        exclude group: 'com.android.support', module: 'support-annotations:22.2.1'
    }
    androidTestImplementation('com.android.support.test:rules:0.3') {
        exclude group: 'com.android.support', module: 'support-annotations:22.2.1'
    }
    androidTestImplementation('com.android.support.test.espresso:espresso-intents:2.2') {
        exclude group: 'com.android.support', module: 'support-annotations:22.2.1'
    }
    androidTestImplementation('com.android.support.test.espresso:espresso-contrib:2.2') {
        exclude group: 'com.android.support', module: 'app-compat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'support-annotations:22.2.1'
        exclude module: 'recyclerview-v7'

    }
    androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
    androidTestImplementation "com.android.support:support-annotations:$supportVersion"
    implementation project(':eventsource_android-release')
    implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
    debugImplementation 'com.letv.sarrsdesktop:BlockCanaryExJRT:0.9.5.3'
    releaseImplementation 'com.letv.sarrsdesktop:BlockCanaryExJRTNoOp:0.9.5.3'
    testImplementation 'com.letv.sarrsdesktop:BlockCanaryExJRTNoOp:0.9.5.3'


    implementation 'me.mvdw.recyclerviewmergeadapter:recyclerviewmergeadapter:2.0.0'
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.1'
    releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
    testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'

    implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
    implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
    implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
    implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion"
    implementation 'io.reactivex.rxjava2:rxjava:2.1.2'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
    implementation 'com.github.ReactiveX:RxKotlin:2.1.0'
    implementation 'com.gojuno.koptional:koptional-rxjava2-extensions:1.2.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.newrelic.agent.android:android-agent:5.14.0'
    implementation 'org.jsoup:jsoup:1.10.3'
}

共有1个答案

田修为
2023-03-14

我刚刚在一个新的kotlin项目中尝试了类似的build.gradle设置,它就构建了。不幸的是,我不能使用你所有的libs和你的确切设置,但也许这只是一个顺序问题。这是我的

Build.Gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

kapt {
    generateStubs = true
}

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "nice.fontaine.kottest"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'com.jakewharton:butterknife:6.1.0'
    annotationProcessor 'com.jakewharton:butterknife:6.1.0'
    implementation('de.keyboardsurfer.android.widget:crouton:1.8.5@aar') {
        exclude group: 'com.google.android', module: 'support-v4'
    }
    implementation 'com.google.dagger:dagger:2.10'
    kapt 'com.google.dagger:dagger-compiler:2.10'
    kapt 'com.android.databinding:compiler:3.0.0'

    implementation 'de.greenrobot:eventbus:2.4.0'
    implementation 'com.mcxiaoke.volley:library:1.0.19'

    implementation 'com.google.code.gson:gson:2.8.0'
    implementation "com.google.android.gms:play-services-places:11.6.0"
    implementation "com.google.android.gms:play-services-plus:11.6.0"
    implementation "com.google.android.gms:play-services-analytics:11.6.0"
    implementation "com.google.android.gms:play-services-auth:11.6.0"
    implementation "com.google.android.gms:play-services-gcm:11.6.0"
    implementation "com.google.android.gms:play-services-ads:11.6.0"

    implementation "com.android.support:appcompat-v7:26.1.0"
    implementation "com.android.support:support-v13:26.1.0"
    implementation "com.android.support:recyclerview-v7:26.1.0"
    implementation "com.android.support:design:26.1.0"
    implementation "com.android.support:support-annotations:26.1.0"
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:multidex:1.0.2'

    implementation 'commons-io:commons-io:2.4'
    implementation 'org.apache.commons:commons-lang3:3.1'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
    implementation 'com.google.ads.mediation:facebook:4.26.1.0'
    implementation 'com.facebook.android:audience-network-sdk:4.26.1'
    implementation 'org.jboss.netty:netty:3.2.10.Final'

    //Testing
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:1.10.19'
    androidTestImplementation 'com.android.support:multidex:1.0.2'
    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test.espresso:espresso-web:3.0.1'
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2') {
        exclude group: 'com.android.support', module: 'support-annotations:22.2.1'
    }
    androidTestImplementation('com.android.support.test:runner:0.3') {
        exclude group: 'com.android.support', module: 'support-annotations:22.2.1'
    }
    androidTestImplementation('com.android.support.test:rules:0.3') {
        exclude group: 'com.android.support', module: 'support-annotations:22.2.1'
    }
    androidTestImplementation('com.android.support.test.espresso:espresso-intents:2.2') {
        exclude group: 'com.android.support', module: 'support-annotations:22.2.1'
    }
    androidTestImplementation('com.android.support.test.espresso:espresso-contrib:2.2') {
        exclude group: 'com.android.support', module: 'app-compat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'support-annotations:22.2.1'
        exclude module: 'recyclerview-v7'

    }
    androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
    androidTestImplementation "com.android.support:support-annotations:26.1.0"
    implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
    debugImplementation 'com.letv.sarrsdesktop:BlockCanaryExJRT:0.9.5.3'
    releaseImplementation 'com.letv.sarrsdesktop:BlockCanaryExJRTNoOp:0.9.5.3'
    testImplementation 'com.letv.sarrsdesktop:BlockCanaryExJRTNoOp:0.9.5.3'

    implementation 'me.mvdw.recyclerviewmergeadapter:recyclerviewmergeadapter:2.0.0'
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.1'
    releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
    testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'

    implementation "com.squareup.retrofit2:retrofit:2.3.0"
    implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
    implementation "com.squareup.retrofit2:converter-gson:2.3.0"
    implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
    implementation 'io.reactivex.rxjava2:rxjava:2.1.2'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
    implementation 'com.gojuno.koptional:koptional-rxjava2-extensions:1.2.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.newrelic.agent.android:android-agent:5.14.0'
    implementation 'org.jsoup:jsoup:1.10.3'
}

至少我可以用这个测试来验证

kapt 'com.android.databinding:compiler:3.0.0' 
 类似资料:
  • 克隆此项目时https://github.com/artem-zinnatullin/droidcon-nyc-2017-puzzlers.git 该项目未能建立,我得到了一个错误。这似乎是rxjava lib中的问题,但我找不到。 }

  • 不管怎样,现在这个构建由于这个错误而失败,我不知道如何解决它: 错误:package some.package.impl不存在 导入一些。package.impl.roundaboutimpl; 提前感谢!

  • 问题内容: 我对Gradle(和Java 9,说实话)还很陌生,并且我正在尝试使用Gradle构建一个简单的库项目,该项目混合了Java 9和Kotlin。更详细地讲,在Java中有一个接口,在Kotlin中有一个实现。我会在Kotlin中做所有事情,但是无论如何都是Java,所以我决定采用这种方式。 我建立在IntelliJ Idea的基础上,外部定义了1.2.0 kotlin插件和gradle

  • 这是用Gradle构建Kotlin+Java9项目的后续。在链接后使用Groovy的Gradle。在我的情况下,使用Kotlin DSL。 基本上我有一个梯度项目与以下结构(只有相关的内容在这里): 问题:如何让链接的post(或任何其他解决方案)中提供的解决方案运行,以便使用Java9/10环境编译带有Gradle的Kotlin DSL的Kotlin项目?

  • 当我导入此接口并尝试调用方法时,它将失败,并出现以下错误: 我已经创建了一个intellij kotlin应用程序,它的工作是正确的。是新Kotlin gradle插件的bug吗?

  • 我正在创建一个新项目(使用IntelliJ IDEA),该项目将使用: 分级作为构建系统 构建脚本的Kotlin DSL “组织”的Java 9模块 科特林语作为主要语言 我有问题设置Gradle正确地建立我的项目。我找到的大多数示例都是针对Groovy而不是Kotlin DSL的,而且大多数示例只覆盖了我想要的一些特性,而不是全部。 lib/build.gradle.kts 执行此操作时,配置将