You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IntelliJ IDEA Ultimate添加mysql-connector依赖失败,报dex错误求助

Fixing 'Return code 1 for dex process' After Adding mysql-connector-java Jar in IntelliJ IDEA

Hey there, let's tackle this dex error you're facing after manually adding the MySQL connector jar. This issue typically ties into Android's dex compilation process—either duplicate dependencies, method count limits, or compatibility hiccups. Here are some targeted fixes to try:

  • Check for duplicate MySQL dependencies
    It's possible your project already has the MySQL connector included via Gradle (in your build.gradle file) and adding the jar manually creates a conflict. Open your app-level build.gradle and look for lines like implementation 'mysql:mysql-connector-java:5.1.46'. If you find it, remove either the manual jar or the Gradle dependency, then sync and rebuild.

  • Enable Multidex (if you hit the 65k method limit)
    The dex error often happens when your project exceeds Android's default 65536 method count limit. To fix this:

    1. In your app-level build.gradle, add multidexEnabled true inside the defaultConfig block:
      android {
          defaultConfig {
              // ... other configs
              multidexEnabled true
          }
      }
      
    2. If you don't have a custom Application class, add the Multidex dependency:
      dependencies {
          implementation 'com.android.support:multidex:1.0.3'
      }
      
    3. If you do have a custom Application class, make it extend MultiDexApplication instead of Application, or override the attachBaseContext method:
      @Override
      protected void attachBaseContext(Context base) {
          super.attachBaseContext(base);
          MultiDex.install(this);
      }
      
  • Verify jar compatibility and try a different version
    The mysql-connector-java-5.1.46 jar is designed for Java SE, not specifically Android. While it can work, newer versions might have better compatibility, or you could try a lightweight alternative built for Android (stick to official/trustworthy options). If you stick with 5.1.46, ensure it's the only MySQL jar in your project.

  • Clean and rebuild your project (clear cache)
    Sometimes cached build files cause dex issues. Try these steps:

    1. Go to Build > Clean Project in IntelliJ.
    2. Then go to Build > Rebuild Project.
    3. If that doesn't work, delete the .idea folder, build folders (both app-level and project-level), then re-import your project into IntelliJ.
  • Increase dex heap size
    The dex process might be running out of memory. Add this to your app-level build.gradle inside the android block:

    dexOptions {
        javaMaxHeapSize "4g"
    }
    

    This allocates more memory to the dex compiler, which can resolve memory-related failures.

Start with the duplicate dependency check first—it's the most common culprit. If that doesn't work, move through the other steps one by one.

内容的提问来源于stack exchange,提问作者AcidRogue

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:28:02