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

如何构建并通过Maven发布Flutter AAR包?

Publishing Flutter-Generated AAR to Maven Repository

Got it, let's break down how to publish your Flutter-built AAR to a Maven repo so your team can integrate it seamlessly. Here's a step-by-step guide tailored for your scenario:

1. Configure Gradle Publishing in Your Flutter Module

First, you need to add Maven publishing settings to your Flutter module's Android build script. Open the android/build.gradle file in your Flutter project and update it with the following:

plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'maven-publish' // Add this plugin to enable publishing functionality
}

android {
    // Keep your existing Android configuration (compileSdkVersion, defaultConfig, etc.)
}

dependencies {
    // Keep your existing dependency declarations
}

publishing {
    publications {
        mavenAar(MavenPublication) {
            from components.release // Target the release build of your AAR
            // Replace these values with your project's unique identifiers
            groupId = 'com.yourteam.flutter'
            artifactId = 'your-flutter-module'
            version = '1.0.0'
        }
    }

    repositories {
        maven {
            // Replace with your Maven repo URL (could be a private remote repo or local shared directory)
            url = uri("https://your-team-maven-repo.com")
            // Add credentials if your repository requires authentication
            credentials {
                username = "your-repo-username"
                password = "your-repo-password"
            }
        }
    }
}

2. Build and Publish the AAR

Now generate the latest AAR and push it to your Maven repo:

  • First, build the AAR from your Flutter project root:
    flutter build aar
    
  • Then run the Gradle publish task to upload the AAR to your repo:
    # For macOS/Linux
    ./gradlew publishMavenAarPublicationToMavenRepository
    
    # For Windows
    gradlew.bat publishMavenAarPublicationToMavenRepository
    

3. Verify the Publication

Check your Maven repository to confirm the AAR (and its accompanying POM file) is present under the groupId/artifactId/version path you specified. This ensures the upload was successful.

4. Team Integration Steps

Your team members can now add the dependency to their native Android projects in just two steps:

  1. In their project's root build.gradle, add your Maven repo:
    repositories {
        maven {
            url = uri("https://your-team-maven-repo.com")
            credentials {
                username = "team-repo-username"
                password = "team-repo-password"
            }
        }
    }
    
  2. In their app module's build.gradle, add the Flutter module dependency:
    dependencies {
        implementation 'com.yourteam.flutter:your-flutter-module:1.0.0'
    }
    

Key Notes & Troubleshooting

  • Versioning: Always increment the version value when publishing updates to avoid dependency conflicts.
  • Local Repo: If using a shared local directory as your Maven repo, replace the url with a local path like uri("../shared-maven-repo").
  • Dependencies: The generated POM file automatically includes all your Flutter module's dependencies, so your team won't need to add them manually.
  • Error Handling: If publishing fails, check Gradle's terminal output for specific issues (e.g., invalid credentials, network access problems, or misconfigured repo paths).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 21:47:41