[英]DuplicateFileException in apk build using Kotlin
I am trying to build a basic app using Kotlin/Anko but I am getting the following duplicate file exception 我正在尝试使用Kotlin / Anko构建基本应用,但出现以下重复文件异常
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: C:\\Users\\mahesh.gradle\\caches\\modules-2\\files-2.1\\org.jetbrains.kotlin\\kotlin-runtime\\1.0.6.\\3562c66f648480d3bd4f76cff722488ced13445b\\kotlin-runtime-1.0.6.jar File2: C:\\Users\\mahesh.gradle\\caches\\modules-2\\files-2.1\\org.jetbrains.kotlin\\kotlin-compiler-embeddable\\1.0.6\\4008eb91a337b377dae7e4572b8b543e5321f549\\kotlin-compiler-embeddable-1.0.6.jar 任务':app:transformResourcesWithMergeJavaResForDebug'的执行失败。> com.android.build.api.transform.TransformException:com.android.builder.packaging.DuplicateFileException:在APK kotlin / internal / internal.kotlin_builtins File1中复制的重复文件:C: \\ Users \\ mahesh.gradle \\ caches \\ modules-2 \\ files-2.1 \\ org.jetbrains.kotlin \\ kotlin-runtime \\ 1.0.6。\\ 3562c66f648480d3bd4f76cff722488ced13445b \\ kotlin-runtime-1.0.6.jar File2:C:\\ Users \\ mahesh.gradle \\缓存\\模块-2 \\文件-2.1 \\ org.jetbrains.kotlin \\科特林编译可嵌入\\ 1.0.6 \\ 4008eb91a337b377dae7e4572b8b543e5321f549 \\科特林编译可嵌入-1.0.6.jar
Following is the code for the app level gradle file: 以下是应用程序级别gradle文件的代码:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
buildscript {
ext.kotlin_version = '1.0.6'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
repositories {
jcenter()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.kotlin.androdikotlinexample"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
//kotlin
compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
//anko
compile "org.jetbrains.anko:anko-design:0.8.3"
compile "org.jetbrains.anko:anko-support-v4:0.8.3"
compile "org.jetbrains.anko:anko-sdk15:0.8.3"
compile 'org.jetbrains.anko:anko-appcompat-v7:0.8.3'
}
Following is the code for Project level gradle file: 以下是项目级别gradle文件的代码:
buildscript {
ext.kotlin_version = '1.0.6'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And this is the basic code for the MainUI file 这是MainUI文件的基本代码
class MainUI : AnkoComponent<MainActivityKotlin> {
override fun createView(ui: AnkoContext<MainActivityKotlin>): View = with(ui) {
coordinatorLayout {
verticalLayout {
// maybe put some content here
}
floatingActionButton {
imageResource = android.R.drawable.ic_menu_edit
onClick {
ui.owner.startActivityForResult<MainActivityKotlin>(1)
}
}.lparams {
gravity = Gravity.BOTTOM or Gravity.END
}
}
}
}
And the content is set on MainActivityKotlin file using the method MainUI().setContentView(this)
in its onCreatemethod
. 然后使用其onCreatemethod
MainUI().setContentView(this)
方法在MainActivityKotlin文件上设置内容。
I have tried deleting the gradle cache and building the project again but nothing works. 我尝试删除gradle缓存并再次构建项目,但是没有任何效果。 Please let me know where am I going wrong? 请让我知道我要去哪里错了?
Remove compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
from your gradle 从compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
删除compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
Remove also all buildscript
section from you app level gradle 同时从您的应用程序级别gradle中删除所有buildscript
部分
Try this one: 试试这个:
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile ("org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version") {
transitive = false
}
Also you don't need the android-extensions dependency anymore, as it's bundled into the plugin. 另外,您不再需要android-extensions依赖项,因为它已捆绑到插件中。 Just having the apply plugin: 'kotlin-android-extensions'
in your gradle is enough. 仅在apply plugin: 'kotlin-android-extensions'
中安装apply plugin: 'kotlin-android-extensions'
就足够了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.