Android Studio生成.jar文件时无法找到bundle文件夹问题咨询
bundles Directory When Creating JAR in Android Studio Hey there, I've run into this exact issue before—those directory structure changes in the Android Gradle Plugin (AGP) can be so frustrating! The problem here is that the build/intermediates/bundles/ path you're referencing was deprecated starting around AGP 3.0+. Newer AGP versions use a completely different directory structure for compiled library outputs, which is why that folder doesn't exist for you.
Let's get your JAR packaging working again with these steps:
1. Update the Source Path in Your Gradle Task
Replace the outdated from path with the correct one for modern AGP versions (7.x/8.x):
task createJar(type: Copy){ from('build/intermediates/aar_main_jar/release/') // This is the new path for compiled classes into('libs/') include('classes.jar') rename('classes.jar','logmanagmentlib.jar') }
If you want a more reliable approach that works across most AGP versions, you can extract the classes.jar directly from the AAR file your library module generates (since libraries default to building AARs):
task createJar(type: Copy){ from zipTree('build/outputs/aar/logmanagmentlib-release.aar') // Replace with your library's actual AAR name into('libs/') include('classes.jar') rename('classes.jar','logmanagmentlib.jar') }
2. Tweak Your Task Dependencies
Instead of relying on the full build task (which runs a ton of unnecessary steps), depend on assembleRelease to only build the release outputs you need:
createJar.dependsOn(deleteJar, assembleRelease)
3. Run the Task and Verify
After updating the code, run the createJar task either from the Gradle panel (look under Tasks > other > createJar) or via terminal:
./gradlew createJar
You should now see your logmanagmentlib.jar pop up in the libs/ directory.
Quick side note: Make sure you're working with an Android Library module (not an Application module)—JAR packaging is designed for reusable libraries. If you're trying to package an app module into a JAR, you'll need to refactor your core code into a library module first.
内容的提问来源于stack exchange,提问作者Sasi

