Wish Improved IDE support for .AAR files

warwound

Expert
Licensed User
Longtime User
Following on from my thread here, i have established that the IDE does not fully support .AAR android library files.

If an .AAR library contains a native .SO library file then the IDE will not compile that .SO file into your .APK.
Your app will fail with an UnsatisfiedLinkError.

Here is the file structure of my .AAR library:

videowidget.aar\jni
videowidget.aar\jni\armeabi-v7a
videowidget.aar\jni\armeabi-v7a\libpano_video_renderer.so
videowidget.aar\res
videowidget.aar\AndroidManifest.xml
videowidget.aar\classes.jar
videowidget.aar\R.txt

The contents of the 'jni' folder must be compiled into my .APK but that does not happen.
Android fails to find the library 'pano_video_renderer' and my app crashes.

I have extracted the 'jni' folder, renamed it to 'lib' then added it to my library source (which i then compile with SLC).
In order to do that i had to create a new folder named 'additional' in my library source and add the 'lib' folder there:

MySourceFolder\additional
MySourceFolder\additional\lib
MySourceFolder\additional\lib\armeabi-v7a
MySourceFolder\additional\lib\armeabi-v7a\libpano_video_renderer.so
MySourceFolder\bin
MySourceFolder\libs
MySourceFolder\src

Works perfectly but isn't ideal.
When Google update their GoogleVR .AARs i'll need to jump through hoops to update and recompile my library.

Can i ask Erel if the 'jni' folder is the only folder found in an .AAR that is not supported by the IDE?
Are there other .AAR folders that the IDE would ideally support?
 

warwound

Expert
Licensed User
Longtime User
Can a b4a library be created as an .AAR file?
Such a b4a library would consist of:

MyLibraryName.aar
MyLibraryName.xml
 

moster67

Expert
Licensed User
Longtime User
Currently the IDE supports the following AAR features:
- Resources
- Assets
- Inner jars
- AndroidManifest.xml (for the resources package).

Has this remained the same or are native libs supported now within the aar or do we need to still create a separate folder for them?
 

warwound

Expert
Licensed User
Longtime User
This is still the case. However you don't need to create a separate folder. You can put the so files inside the referenced jar or in a jar inside the aar file.

It's nearly a year on from the last post in this thread.
Does the IDE now support the 'jni' folder in .aar libraries and compile .so files into the .apk?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User

warwound

Expert
Licensed User
Longtime User
Hmmm i can't get this to work...

I have b4a version 8.00 installed.
I'm wrapping the latest version of the GoogleVr library which depends on library file libpanorenderer.so located in the jni folder of sdk-panowidget-1.130.0.aar.

I compile my project and get a runtime error:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/imagineear.api.panoramaviewtest-1/base.apk"],nativeLibraryDirectories=[/data/app/imagineear.api.panoramaviewtest-1/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libpanorenderer.so"
I open my compiled apk and sure enough it doesn't contain libpanorenderer.so.

I recompile my library jar so that it contains libpanorenderer.so in lib/armeabi-v7a folder.
I open sdk-panowidget-1.130.0.aar and remove it's jni folder, this is not essential but enables me to be sure of where the compiler gets it's libpanorenderer.so from.
Finally i recompile my project and it works fine, a quick look in the apk shows libpanorenderer.so exists.

You can take a look at the sdk-panowidget-1.130.0.aar library file here:
https://github.com/googlevr/gvr-android-sdk/blob/master/libraries/sdk-panowidget-1.130.0.aar

Am i doing something wrong?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Am i doing something wrong?
Nothing. There is still an issue with the way the jni folder is treated...
It is fixed for the next update.

You can workaround it by adding a "stub" jar into the aar. There is a small text file inside which will cause the compiler to include raw resources from the aar.
SS-2018-03-22_13.41.12.png
 

Attachments

  • stub.jar
    118 bytes · Views: 332

warwound

Expert
Licensed User
Longtime User
When this feature is working, and the library .aar file contains jni subfolders such as 'arm64-v8a', 'armeabi-v7a' and 'x86' then i presume the compiler will compile the .so files from all three folders into the .apk?

That might seem like a silly question but i am working with a specific custom tablet and currently only require support for the 'armeabi-v7a' CPU architecture.
Currently i remove the folders for other CPU architectures such as 'arm64-v8a' and 'x86' to avoid unnecessary bloat in my apks.

I'll probably end up removing the unwanted folders from each .aar jni folder to continue to avoid the apk bloat when this feature is working.
Unless there's way to tell the compiler not to support a particular CPU archiutecture?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
When this feature is working, and the library .aar file contains jni subfolders such as 'arm64-v8a', 'armeabi-v7a' and 'x86' then i presume the compiler will compile the .so files from all three folders into the .apk?
Yes. You can try it with the above workaround.

Unless there's way to tell the compiler not to support a particular CPU archiutecture?
No. All files under the jni folder will be included.
 
Top