Android Studio 3.0.1中Whatchap项目Dex合并失败求助
Hey there, let's work through this dex merging issue you're hitting. I've gone through your Gradle config and the steps you've already tried, so here are targeted solutions to resolve the problem:
1. Remove the Conflicting Local JAR
Your dependencies include implementation files('libs/sun.misc.BASE64Decoder.jar')—this is likely a key culprit. The sun.misc.BASE64Decoder class conflicts with Android's native android.util.Base64 utility, and including this external JAR creates duplicate class definitions that break dex merging.
Fix Steps:
- Delete the
sun.misc.BASE64Decoder.jarfile from your project'slibsfolder - Remove the corresponding line from your app-level
build.gradledependencies:dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' 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' // Remove this line: implementation files('libs/sun.misc.BASE64Decoder.jar') implementation 'com.android.support:support-v4:26.1.0' implementation 'com.google.android.gms:play-services-gcm:11.2.0' } - Replace any usage of
sun.misc.BASE64Decoderin your code with Android'sandroid.util.Base64instead.
2. Resolve Dependency Version Conflicts
Your support library version (26.1.0) and Google Play Services version (11.2.0) might be pulling in conflicting sub-dependencies. To identify and fix this:
- Run this command in your project root to analyze dependency trees:
./gradlew app:dependencies - Look for duplicate libraries or version mismatches. For example, if Play Services includes a conflicting support library, exclude it:
implementation ('com.google.android.gms:play-services-gcm:11.2.0') { exclude group: 'com.android.support', module: 'support-v4' }
3. Perform a Deep Clean of Build Caches
Regular clean/rebuild might not clear all corrupted artifacts. Try this:
- Close Android Studio
- Delete these folders:
- Project root's
.gradlefolder app/buildfolder- System-level Gradle cache (Windows:
C:\Users\<YourUsername>\.gradle\caches; Mac/Linux:~/.gradle/caches)
- Project root's
- Reopen Android Studio, sync Gradle files (
File > Sync Project with Gradle Files), then rebuild the project.
4. Verify Complete MultiDex Configuration
You mentioned adding multiDexEnabled true, but ensure the setup is full:
- Confirm it's in your
defaultConfigblock:defaultConfig { applicationId "stmik.iax.whatchap" minSdkVersion 16 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" multiDexEnabled true // Make sure this exists } - Since your
minSdkVersionis below 21, add the MultiDex dependency:implementation 'com.android.support:multidex:1.0.3' - Update your Application class (or create one if you don't have it):
public class WhatchapApplication extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } } - Reference this class in your
AndroidManifest.xml:<application android:name=".WhatchapApplication" <!-- other attributes --> > </application>
Start with step 1 first—it's the most likely fix for your specific setup. If that doesn't work, work through the other steps one by one.
内容的提问来源于stack exchange,提问作者Ming Ky Chandra

