Android Studio中建立失效与科特林(Android Studio build faile

2019-09-28 03:54发布

    :app:mergeDebugAssets
            :app:processDebugJavaRes UP-TO-DATE
            :app:transformResourcesWithMergeJavaResForDebug FAILED

            FAILURE: Build failed with an exception.

            * What went wrong:
            Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
            > com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK kotlin/internal/internal.kotlin_builtins
            File1: /Users/KD/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-compiler-embeddable/1.0.4/172b43fbc03b521fed141484b212d6725fa671a9/kotlin-compiler-embeddable-1.0.4.jar
            File2: /Users/KD/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-runtime/1.0.4/8e25da5e31669f5acf514bdd99b94ff5c7003b3b/kotlin-runtime-1.0.4.jar

我的build.gradle:

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

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.app2par.ctime"
        minSdkVersion 16
//        minSdkVersion 21
//        targetSdkVersion 23
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        multiDexEnabled false
//        multiDexEnabled true
    }
    dexOptions {
        preDexLibraries true
        javaMaxHeapSize "2g" // Use gig increments depending on needs
        incremental true
    }
    buildTypes {
        debug {
            minifyEnabled false
//            testCoverageEnabled true
//            ext.betaDistributionReleaseNotes = getCrashlyticsBetaMessage()
//            ext.betaDistributionGroupAliases = 'team'
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
//    dataBinding {
//        enabled = true
// https://code.google.com/p/android/issues/detail?id=187443&q=attachments%3D0&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
//    }
    lintOptions {
        abortOnError false
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile project(':firebasesync')
    compile project(':liboid')
    compile project(':cloudtimemodel')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1') {
        exclude group: 'com.android.support'
    }
    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
        exclude group: 'com.android.support'
    }
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    //    compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
    //        transitive = true;
    //    }
    //    compile 'com.google.android.gms:play-services:5.0.89'
    //    compile 'com.google.android.gms:play-services:7.0.0'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
    // compile   'com.firebase:firebase-client-android:2.0.3.+'
//    compile 'com.google.android.gms:play-services-safetynet:8.3.0'
//    compile 'com.google.android.gms:play-services-auth:8.3.0'

    compile 'com.google.android.gms:play-services-plus:7.0.0' // play-services-plus:7.0.0 : office-mover
//    compile 'com.google.android.gms:play-services-auth:8.3.0' // play-services-auth:8.3.0 : ShoppingList++

    //    compile 'com.google.android.gms:play-services-identity:7.0.0'
}
buildscript {
//    ext.kotlin_version = '1.0.0-rc-1036'
    ext.kotlin_version = '1.0.4'
    repositories {
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
//        classpath 'org.ajoberstar:grgit:1.1.0'
//        classpath 'io.fabric.tools:gradle:1.+'
//        classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.5.0-x'
    }
}
repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
}

如何解决或诊断呢?

Answer 1:

您应该删除compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"从你的dependencies部分,并将其移到buildscript { dependencies { ... } }



Answer 2:

你没把compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"在错误build.gradle文件

您可以使用kotlin插件的内置的转换器来处理这个问题。 据Kotlin Docs

在项目配置科特林

当添加新的科特林文件,IntelliJ IDEA的(和Android工作室)会自动提示我们,我们是否要配置科特林运行的项目。 然而,目前,将现有的Java文件不提示此操作。 因此,我们必须手动调用它(通过查找动作 ):

然后,我们会提示科特林的版本。 选择最新的从已安装的版本列表。

我们配置科特林后,该应用程序的build.gradle文件应该被更新。 现在我们可以看到,应用插件:“科特林-机器人”,加入的依赖关系。

(有关详细信息如何设置为gradle这个项目,请使用摇篮 )

做的最后一件事是同步的项目。 我们可以按Sync Now在提示或调用操作同步工程与摇篮文件

来源: https://kotlinlang.org/docs/tutorials/kotlin-android.html

检查上面的链接以获取更多信息。

希望这将有助于。



Answer 3:

你需要申请只有一个插件,在您的情况apply plugin: 'kotlin-android-extensions' ,只compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"这种依赖性。 它为我工作



文章来源: Android Studio build failed with Kotlin