我需要将 .aar 文件转换为 .jar
根据定义,AAR 不是 JAR,不一定要“转换”成 JAR。
通常,如果工件以 AAR 而不是 JAR 的形式分发,那是因为工件的一部分不仅仅是 Java 代码。
我的意思是,在 Android SDK 中,extras/android/m2repository/com/android/support/support-v4 库只有 24.1 版本之前的类
正确。从那时起,support-v4 只是传递依赖的容器。您将在工件旁边的 POM 文件中看到它们的列表。
例如,25.3.1 POM 文件显示了当您在 AAR-artifact-aware IDE(Android Studio、IntelliJ IDEA 等)中使用 support-v4 时将拉入的所有工件:
<?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>
正如您从 <type> 元素中看到的那样,大多数传递依赖本身就是 AAR。
有时,AAR 只包含一个 JAR。
例如,support-core-utils 的25.3.1 版本——support-v4 引入的 AAR 之一——除了我可以看到的 classes.jar 之外没有任何重要意义。
但是,其他 AAR 具有 JAR 之外的内容。例如,support-compat 和 support-media-compat 具有 AIDL 文件。其他 AAR(例如 appcompat-v7)拥有资源或资产。如果您尝试仅使用 AAR 之外的 JAR,并尝试使用期望这些资源或 AIDL 文件或其他任何存在的类,您的应用将会崩溃。
您可以尝试将 AAR 转换为旧式 Eclipse 库项目。俗话说,你的里程可能会有所不同。另外,我不知道 IBM MobileFirst 是否支持库项目。