Kotlin的Android Studio构建失败 [英] Android Studio build failed with Kotlin
问题描述
:app:mergeDebugAssets
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug FAILED
FAILURE:构建失败除了例外。
*出错:
任务':app:transformResourcesWithMergeJavaResForDebug'的执行失败。
> com.android.build.api.transform.TransformException:com.android.builder.packaging.DuplicateFileException:复制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
buildToolsVersion23.0.2
defaultConfig {
applicationIdcom.app2par.ctime
minSdkVersion 16
// minSdkVersion 21
// targetSdkVersion 23
targetSdkVersion 22
versionCode 1
versionName1.0
testInstrumentationRunnerandroid.support.test.runner.AndroidJUnitRunner
multiDexEnabled false
// multiDexEnabled true
}
dexOptions {
preDexLibraries true
javaMaxHeapSize2g//根据需要使用gig增量
增量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.srcDir s + ='src / main / kotlin'
}
// dataBinding {
//启用= 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
排除'META-INF / LICENSE'
排除'META-INF / LICENSE-FIREBASE.txt'
排除'META-INF / NOTICE'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
的依赖关系{
编译fileTree(包括:['* .jar'],dir:'libs')
编译项目(':firebasesync')
编译项目(':liboid' )
compile project(':cloudtimemodel')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1'){
排除组:'com.android.support'
}
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1'){
exclude group:' com.android.support'
}
compileorg.jetbrains.kotlin:kotlin-stdlib:$ kotlin_version
// compile('com.crashlytics.sdk.android:crashlytics:2.5 .5 @ aar'){
// transitive = true;
//}
//编译'com.google.android.gms:play-services:5.0.89'
//编译'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
//编译'com.firebase:firebase-client-android:2.0.3。+'
//编译'com.google.android.gms:play-services-safetynet:8.3.0'
//编译'com.google.android.gms:play-services-auth:8.3。 0'
编译'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.ko tlin_version ='1.0.0-rc-1036'
ext.kotlin_version ='1.0.4'
存储库{
mavenCentral()
maven {url'https:// maven .fabric.io / public'}
}
依赖关系{
classpathorg.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'
}
}
知识库{
mavenCentral()
maven {url'https://maven.fabric.io/public'}
}
如何解决或诊断此问题? p>
您确实已将编译为org.jetbrains.kotlin:kotlin-android-extensions:$ kotlin_version / code>在错误的
build.gradle
文件中
您可以使用 kotlin
插件的内置转换器处理它。根据 Kotlin Docs
:
在项目中配置Kotlin
添加新的Kotlin文件时,IntelliJ IDEA(和Android Studio)
会自动提示我们是否要为项目配置
Kotlin运行时。但是,目前,转换
现有Java文件不会提示此操作。因此,我们必须
手动调用它(通过
然后提示我们输入Kotlin版本。选择已安装版本列表中的最新
。
在我们配置Kotlin之后,应该更新应用程序
的build.gradle文件。现在我们可以看到apply plugin:'kotlin-android'
,并且添加了依赖关系。
(更多详情如何为你的项目设置gradle ,请检查
发件人: https://kotlinlang.org/docs/tutorials/kotlin
$ / b
希望它会有帮助。: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
My 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' } }
How to fix or diagnose this?
解决方案You did put
compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
in the wrongbuild.gradle
fileYou may use
kotlin
plugin's build-in converters to deal with this. According toKotlin Docs
:Configuring Kotlin in the project
When adding a new Kotlin file, IntelliJ IDEA (and Android Studio) automatically prompts us as to whether we'd like to configure the Kotlin runtime for the project. However, currently, converting existing Java file does not prompt this action. Therefore we have to invoke it manually (via Find Action):
We are then prompted for the version of Kotlin. Choose the latest available from the list of installed versions.
After we configure Kotlin, build.gradle file for the application should be updated. Now we can see that apply plugin: 'kotlin-android' and the dependencies were added.
(For more details how to set up gradle for your project, please check Using Gradle)
The last thing to do is to sync the project. We can press
Sync Now
in a prompt or invoke an action Sync Project with Gradle Files.From: https://kotlinlang.org/docs/tutorials/kotlin-android.html
Check link above for more information.
Hope it will help.
这篇关于Kotlin的Android Studio构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!