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

导出Android Library为AAR文件时找不到aar文件夹,求解决方案

解决Android Library模块无法生成AAR文件的问题

Hey there! Let's figure out why your Android Library module isn't generating that AAR file you need. I've run into this exact issue before, so here's what you should check and fix:

1. 先确认你的模块是真正的Android Library

First things first—make sure your module is set up as a Library, not an Application. Open your module's build.gradle (or build.gradle.kts if you're using Kotlin DSL) and check the top plugin declaration:

  • It should say id 'com.android.library' (for Groovy) or id("com.android.library") (for Kotlin)
  • If it's com.android.application, that's an app module—it only builds APKs, not AARs. Change it to the library plugin, sync your project, and try building again.

2. 使用正确的构建方法(别点Build APK!)

The "Build APK" option is for app modules, so it won't generate an AAR for your library. Instead, use one of these reliable methods:

  • Gradle Task (most straightforward): Open the Gradle panel on the right side of Android Studio (if it's hidden, go to View > Tool Windows > Gradle). Navigate to your library module → Tasks → build, then double-click the assemble task. This builds both debug and release AARs, and you'll find them in module-name/build/outputs/aar/ once it finishes.
  • Build Menu Options: Click Build > Make Module 'your-library-module-name' (this only builds your library) or Build > Rebuild Project (cleans and rebuilds everything). Either will generate the AAR if the build succeeds.

3. 排查常见的构建障碍

If you still don't see the aar folder, check these:

  • Fix Build Errors: Look at the Build tab at the bottom of Android Studio—if there are compilation errors (like missing dependencies or code issues), the build will fail and no AAR will be generated. Fix those errors first.
  • Check Module Inclusion: Go to File > Project Structure > Modules, and make sure your library module is checked (it should be included in the build).
  • Clear Cache: Sometimes cached data messes things up. Go to File > Invalidate Caches... > Invalidate and Restart. Once Android Studio reopens, rebuild your module.

Once you get the AAR file, you can just share it directly with others—they can add it as a local dependency in their Android projects.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 06:51:21