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

如何在Android Studio中添加本地Maven项目为依赖?XChange定制适配

Add Your Local Forked XChange Maven Project as an Android Dependency

Got it, let's walk through two reliable methods to hook up your local XChange fork directly to your Android project. No more waiting for Jitpack builds when you're iterating on custom changes—way faster for testing and debugging.

Method 1: Install to Local Maven Repository

This is great if you want to treat your local XChange build like any other Maven dependency, and don't need to edit XChange code constantly.

  • Step 1: Build and install XChange locally
    Open your forked XChange project in IntelliJ IDEA. Open the terminal (or use the Maven tool window) and run:

    mvn clean install -DskipTests
    

    This compiles the project and installs all its modules into your local Maven repository (usually located at ~/.m2/repository). Make sure you note the version number from XChange's pom.xml—you'll need it for the Android dependency.

  • Step 2: Configure your Android project's repositories
    Open your Android project's project-level build.gradle (or settings.gradle if you're using newer Android Studio versions with dependency resolution management). Add mavenLocal() to your repositories list:

    allprojects {
        repositories {
            google()
            mavenCentral()
            mavenLocal() // Add this line
        }
    }
    

    For newer Gradle versions (using dependencyResolutionManagement in settings.gradle):

    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            google()
            mavenCentral()
            mavenLocal()
        }
    }
    
  • Step 3: Add the dependency to your app module
    Open your app-level build.gradle and add the XChange dependency using the same coordinates as you would for the official version (matching the local build's version):

    dependencies {
        implementation 'org.knowm.xchange:xchange-core:your-local-version'
        // Add other XChange modules you need, e.g.:
        // implementation 'org.knowm.xchange:xchange-binance:your-local-version'
    }
    

    Sync your project with Gradle files, and you're good to go.

This is the best option if you're actively modifying XChange code—changes will reflect in your Android project immediately after syncing, no need to re-run mvn install every time.

  • Step 1: Import the XChange module into Android Studio
    Open your Android project, go to File > New > Import Module. Navigate to the root directory of your forked XChange project, select it, and click Finish. Android Studio will automatically detect the Maven structure and set up the module(s).

  • Step 2: Enable Java 8 support in your Android project
    Since XChange uses JDK 8 features like Streams, your Android project needs to enable Java 8 compatibility. Open your app-level build.gradle and add this inside the android block:

    android {
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
        // If you're using Kotlin, add this too:
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }
    
  • Step 3: Add the module dependency
    Still in your app-level build.gradle, add the dependency on the imported XChange modules:

    dependencies {
        implementation project(':xchange-core')
        // Add other modules as needed, e.g.:
        // implementation project(':xchange-binance')
    }
    

    If Android Studio doesn't automatically add the modules to your settings.gradle, you'll need to manually include them:

    include ':app', ':xchange-core', ':xchange-binance'
    
  • Step 4: Sync and test
    Click Sync Project with Gradle Files. Now any changes you make to your local XChange code will be picked up by the Android project on the next sync—perfect for iterative development.

Quick Notes

  • Double-check that the version numbers in Method 1 match exactly what's in your local XChange pom.xml—mismatches will cause Gradle to pull the wrong version.
  • If you run into build errors related to JDK versions, make sure both your XChange project and Android project are configured to use JDK 8 or higher.
  • When you're ready to push changes, you can still use Jitpack as before—this local setup is just for faster development.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 10:23:23