Gradle上的Android应用程序:无法合并dex
我在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.
我有研究这个主题,所以我尝试了一些解决方案,从这里 :
- 清理和重建项目。 没有变化。
- 将gradle中的“编译”更改为“实现”。 没有变化。
- 删除
.gradle
和build
目录。 没有变化。 -
在gradle的
defaultConfig
中添加multiDexEnabled true
。 在这种情况下,我有另一个错误: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 :
我错过了什么?
UPD
看来我发现问题出现之后的那一点。 这是在添加Twilio配置后。 我使用了这个手册: Twilio和Android
这是所有已经做的改变:
-
添加到
build.gradle
:implementation 'com.twilio:client-android:1.2.21'
-
添加到
AndroidManifest
: -
添加到
proguard-rules.pro
# Twilio Client -keep class com.twilio.** { *; } # Apache HttpClient -dontwarn org.apache.http.**
就这样。 在这个变化之前,我没有这个错误
如果你想为你的libs dir读取一个.aar
文件,可以在你的build.gradle
中使用它:
repositories{ flatDir{ dirs 'libs' } } dependencies { compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar') }
但似乎你的问题是multidex(意味着你有超过65K的方法在你的项目中,所以使用这个:
android { defaultConfig { multiDexEnabled true } }
如果你的minSdk <20,那么也使用这个:
compile 'com.android.support:multidex:1.0.1'
希望能帮助到你!!!
- 在“LatLngBounds”构建器上设置最大缩放级别
- 我在java代码中实现了一个在kotlin中定义的接口。 有’空’types不允许在这里
- 如何在kotlin的Grid View和List View之间使用setOnclickListener
- 在多项目设置中ConfigurationsContainer为空
- 在Android设备上使用Java / Kotlin检测音频文件(amr)中的静音
- Kotlin Android打印到控制台
- 应用程序build.gradle.kts文件未解决参考Erros
- 无法使用RxKotlin更改ActionMenuItemView的文本
- 如何检查我的应用程序是否是默认的启动器