简体   繁体   中英

How to convert an .aar file into a .jar

To work with Eclipse IDE in for an IBM MobileFirst Platform project, I need to convert an .aar file into a .jar. I tried to extract the classes.jar file, but it is practically empty, with none class. I mean, at the Android SDK, the extras/android/m2repository/com/android/support/support-v4 libraries only have classes until 24.1 version, from there all the versions bellow, only have the empty classes.jar file. So, what can I do with the classes in these versions?

Trying to clarify a little bit this topic, this question helped me:

Android Archive Library (aar) vs standard jar

Some one knows a process to turn this Android Archive file into a Java Archive file?

I need to convert an .aar file into a .jar

By definition, an AAR is not a JAR and cannot necessarily be "converted" into a JAR.

Frequently, if the artifact is distributed as an AAR, instead of a JAR, that is because there is more than just Java code that is part of the artifact.

I mean, at the Android SDK, the extras/android/m2repository/com/android/support/support-v4 libraries only have classes until 24.1 version

Correct. Since then, support-v4 has merely been a container for transitive dependencies. You will see a list of them in the POM file adjacent to the artifact.

For example, the 25.3.1 POM file shows all of the artifacts that will be pulled in when you use support-v4 in an AAR-artifact-aware IDE (Android Studio, IntelliJ IDEA, etc.):

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.android.support</groupId>
  <artifactId>support-v4</artifactId>
  <version>25.3.1</version>
  <packaging>aar</packaging>
  <dependencies>
    <dependency>
      <groupId>com.android.support</groupId>
      <artifactId>support-compat</artifactId>
      <version>25.3.1</version>
      <type>aar</type>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.android.support</groupId>
      <artifactId>support-media-compat</artifactId>
      <version>25.3.1</version>
      <type>aar</type>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.android.support</groupId>
      <artifactId>support-core-utils</artifactId>
      <version>25.3.1</version>
      <type>aar</type>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.android.support</groupId>
      <artifactId>support-core-ui</artifactId>
      <version>25.3.1</version>
      <type>aar</type>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.android.support</groupId>
      <artifactId>support-fragment</artifactId>
      <version>25.3.1</version>
      <type>aar</type>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

As you can see from the <type> elements, most of those transitive dependencies themselves are AARs.

Sometimes, the AAR does not contain much other than a JAR. For example, the 25.3.1 edition of support-core-utils — one of the AARs that support-v4 pulls in — has nothing of importance other than its classes.jar that I can see.

However, other AARs have things beyond the JAR. For example, support-compat and support-media-compat have AIDL files. Other AARs — such as appcompat-v7 — have resources or assets. If you try just using the JAR out of the AAR, and you try using a class that expects those resources or AIDL files or whatever to exist, your app will crash.

You can attempt to convert an AAR into an old-style Eclipse library project. As the saying goes, your mileage may vary. Plus, I have no idea if IBM MobileFirst supports library projects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM