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

Android Studio导入iextrading4j库失败求助:含MultiDex等错误

Fixing iextrading4j Setup Errors in Android Studio (MultiDex, JSR305, TransformClasses)

Hey there, I’ve helped a few folks work through these exact issues with iextrading4j on Android. Let’s break down the full setup step by step to squash those errors for good.

1. First: Resolve MultiDex Issues

The transformClassesWith... error often ties to hitting Android’s 65k method limit—iextrading4j pulls in several underlying dependencies that can push your project over this threshold. Here’s how to enable MultiDex properly:

  • Update your app-level build.gradle:
    Add the MultiDex dependency and enable it in your defaultConfig:

    android {
        defaultConfig {
            // ... existing configs (minSdkVersion, targetSdkVersion)
            multiDexEnabled true
        }
    }
    
    dependencies {
        // Use this for androidx projects
        implementation 'androidx.multidex:multidex:2.0.1'
        // Or this if you're using the old support library:
        // implementation 'com.android.support:multidex:1.0.3'
    }
    
  • Update your Application class:
    If you have a custom Application class, extend MultiDexApplication instead of the default:

    public class MyStockApp extends MultiDexApplication {
        // ... your existing code here
    }
    

    If you don’t have a custom Application class, add this to your AndroidManifest.xml:

    <application
        android:name="androidx.multidex.MultiDexApplication"
        <!-- ... other attributes -->
    >
    

2. Fix JSR305 (findbugs) Conflict

The findbugs:jsr305:1.3.9 error stems from a dependency clash—Android already includes a version of JSR305, and iextrading4j tries to pull in another. We can exclude this redundant dependency directly from iextrading4j:

  • Add iextrading4j with excluded JSR305:
    In your app-level build.gradle, replace your current iextrading4j line with this (use the version you prefer, 2.1.1 or 2.0.1):

    dependencies {
        // For version 2.1.1
        implementation ('pl.zankowski:iextrading4j-all:2.1.1') {
            exclude group: 'com.google.code.findbugs', module: 'jsr305'
        }
    
        // Or for version 2.0.1
        // implementation ('pl.zankowski:iextrading4j-all:2.0.1') {
        //     exclude group: 'com.google.code.findbugs', module: 'jsr305'
        // }
    }
    
  • Optional: Force JSR305 Version (If Conflicts Persist)
    If you still see JSR305-related errors, add this to your root-level build.gradle to force a compatible version across all dependencies:

    allprojects {
        repositories {
            // ... your existing repos (google(), mavenCentral(), etc.)
        }
    
        configurations.all {
            resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.2'
        }
    }
    

3. Full Working Configuration Example

Here’s how your app-level build.gradle should look when all settings are combined:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 34 // Use your project's target SDK version
    defaultConfig {
        applicationId "com.yourusername.stocktracker"
        minSdkVersion 21 // If targeting below 21, ensure MultiDex is fully set up
        targetSdkVersion 34
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.multidex:multidex:2.0.1'

    // iextrading4j with excluded JSR305 dependency
    implementation ('pl.zankowski:iextrading4j-all:2.1.1') {
        exclude group: 'com.google.code.findbugs', module: 'jsr305'
    }
}

4. Post-Setup Checks

  • Add Internet Permission: Since you’re fetching data from an API, make sure this line is in your AndroidManifest.xml:

    <uses-permission android:name="android.permission.INTERNET" />
    
  • Test with a Simple API Call: Verify the setup works with a basic request (always run network calls on a background thread!):

    new Thread(() -> {
        ICloudClient cloudClient = IEXTradingClient.create();
        try {
            StockQuote appleQuote = cloudClient.execute(new GetQuoteRequestBuilder()
                    .withSymbol("AAPL")
                    .build());
            Log.d("IEX_TEST", "AAPL Latest Price: " + appleQuote.getLatestPrice());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }).start();
    

5. Troubleshooting Remaining Errors

If you still see transformClassesWith... errors:

  • Clean and rebuild your project (Build > Clean Project then Build > Rebuild Project).
  • Invalidate caches and restart Android Studio (File > Invalidate Caches... > Invalidate and Restart).
  • Ensure you’re using the latest version of the Android Gradle Plugin (check your root build.gradle).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:14:07