【发布时间】:2017-12-12 09:57:14
【问题描述】:
我在 Android Studio 中的应用出现错误:
Execution failed for task
':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
我使用 Gradle 和 Kotlin。
Android Studio 3.0.1.
Windows 10 Pro 64.
我在 SO 上研究过这个主题,并尝试了here 的一些解决方案,例如:
- 清理并重建项目。没有变化。
- 将 gradle 中的“编译”更改为“实现”。没有变化。
- 删除
.gradle和build目录。没有变化。 -
在 gradle 中添加
multiDexEnabled true到defaultConfig中。在这种情况下,我还有另一个错误:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. > java.io.IOException: Can't write [G:\work\myapp\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\Public\.gradle\caches\transforms-1\files-1.1\support-core-utils-27.0.2.aar\e1c9881d763269b67bf59dc03d19c305\jars\classes.jar(;;;;;;**.class)] (Duplicate zip entry [classes.jar:android/support/v4/content/PermissionChecker$PermissionResult.class]))
我的build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
multiDexEnabled true
applicationId "myapp"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
applicationIdSuffix ".dev"
}
staging {
debuggable true
applicationIdSuffix ".sta"
}
preproduction {
applicationIdSuffix ".pre"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.basecamp:turbolinks:1.0.7'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
// The Client SDK resides on jCenter
implementation 'com.twilio:client-android:1.2.21'
}
我的AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tunnll.passenger">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.twilio.client.TwilioClientService"
android:exported="false" android:stopWithTask="true"/>
</application>
我错过了什么?
UPD
问题出现后,我似乎找到了重点。这是在添加 Twilio 配置之后。我用过这本手册:Twilio and Android
这是已完成的所有更改:
-
添加到
build.gradle:implementation 'com.twilio:client-android:1.2.21' -
添加到
AndroidManifest:<service android:name="com.twilio.client.TwilioClientService" android:exported="false" android:stopWithTask="true"/> -
添加到
proguard-rules.pro# Twilio Client -keep class com.twilio.** { *; } # Apache HttpClient -dontwarn org.apache.http.**
就是这样。在此更改之前,我没有此错误
【问题讨论】:
-
你的libs文件夹下有什么吗?
-
缓存无效/重启?
-
@global_warming,不,我的项目结构中好像没有libs目录
-
@AswinPAshok,尝试重启,没有结果:(
-
我认为你有冲突的依赖关系。您已在 Gradle 中包含
com.android.support:appcompat-v7:27.0.2,但 turbolinks 库为 compiled with support library25.1.1。因此,请尝试在没有 turbolink 库的情况下进行编译。仍然不确定这是您问题的原因。阅读this 以避免依赖冲突
标签: android android-gradle-plugin kotlin twilio