gpt4 book ai didi

Gradle 上的 Android 应用程序 : Unable to merge dex

转载 作者:行者123 更新时间:2023-11-29 02:34:40 24 4
gpt4 key购买 nike

我的应用程序在 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 的一些解决方案,像那样:

  1. 清理并重建项目。没有变化。
  2. 将 gradle 中的“编译”更改为“实现”。没有变化。
  3. 删除.gradlebuild 目录。没有变化。
  4. 在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:

<?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

这是所有已完成的更改:

  1. 添加到build.gradle:

      implementation 'com.twilio:client-android:1.2.21'
  2. 添加到AndroidManifest:

      <service android:name="com.twilio.client.TwilioClientService" 
    android:exported="false" android:stopWithTask="true"/>
  3. 添加到proguard-rules.pro

      # Twilio Client
    -keep class com.twilio.** { *; }

    # Apache HttpClient
    -dontwarn org.apache.http.**

就是这样。在此更改之前我没有出现此错误

最佳答案

如果您想读取 .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'

希望对您有所帮助!!!

关于Gradle 上的 Android 应用程序 : Unable to merge dex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47769717/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com