Home » Android » android – What is the best way to refer aar from javac?-Exceptionshub

android – What is the best way to refer aar from javac?-Exceptionshub

Posted by: admin February 26, 2020 Leave a comment

Questions:

Many Android libraries like support-v4 was provided as jar file with support-v4-19.1.0.jar, but later they are available as aar file e.g. support-v4-25.1.0.aar. So, jar files can be referenced directly with javac:

javac -classpath library.jar -sourcepath java -d bin java\com\example\*.java

Can also a library.aar be integrated directly with javac? Or what’s the best way?

How to&Answers:

AAR files are specific used by Google for Android. However, javac is a compiler independent of Android and Google. Therefore, with javac is currently no way to access components within the aar container.

The only way is to unpack the aar file and afterwards to use the needed components. The component mentioned in the question corresponds to the classes.jar inside the aar file. For example, the aar files can be used with javac on windows cmd as follows:

rem define a system zip unpacker
set UNZIP="C:\Program Files (x86)\System-Zipz.exe" x -o

rem unzip the aar file
%UNZIP%C:\programming\extras\android\libs\unpacked\support-v4-25.1.0 ^
C:\programming\extras\android\m2repository\com\android\support\support-v7.1.0\support-v4-25.1.0.aar

rem use the extracted classes.jar library
javac -classpath C:\programming\extras\android\libs\unpacked\support-v4-25.1.0\classes.jar -sourcepath java -d bin java\com\example\*.java