Home >Java >javaTutorial >How to Create a JAR File from an Android Studio Project?
Creating a JAR File from an Android Studio Project
Android Studio provides a convenient way to package your project into a JAR file, allowing you to reuse code between projects. Here's a step-by-step guide for creating a JAR file from an Android Studio project:
1. Prepare the Project:
Modify the library project's build.gradle file to add the tasks deleteJar and createJar. Make sure to specify a dependency between createJar and deleteJar, as shown in the example code below:
task deleteJar(type: Delete) { delete 'libs/jars/logmanagementlib.jar' } task createJar(type: Copy) { from('build/intermediates/bundles/release/') into('libs/jars/') include('classes.jar') rename('classes.jar', 'logmanagementlib.jar') } createJar.dependsOn(deleteJar, build)
2. Generate the JAR File:
Navigate to the Gradle panel in Android Studio and expand the tasks for the library project. Find the "createJar" task and double-click it to execute it.
3. Retrieve the JAR File:
Once the task completes successfully, the JAR file will be generated in the specified path (e.g., libs/jars/logmanagementlib.jar).
4. Use the JAR File in Another Project:
Copy the generated JAR file into the libs folder of your target project. Right-click the JAR and select "Add as Library" to include it in the project.
The above is the detailed content of How to Create a JAR File from an Android Studio Project?. For more information, please follow other related articles on the PHP Chinese website!