3

I'm trying to build an app bundle but I'm getting the following error:

File 'root/lib/x86_64-MacOSX-gpp/jni/libjunixsocket-native-2.0.4.jnilib' uses reserved file or directory name 'lib'.

For what I've seen from similar questions, this issue is normally solved juggling dependencies or files in the project structure, but in this case it seems to point to a native library involved in app architecture if i'm not mistaken. Any ideas how to solve this?

Petermonteer
  • 296
  • 4
  • 17

2 Answers2

4

It looks like you are adding a dependency as a jar instead of an aar.

The aar contains the information of what files should be considered as Android resources, native libraries, etc. in the app. A jar is just a plain list of files without Android concept. Because the jar you're depending on contains a directory lib, the files would normally end up being considered as native libraries, but because the files come from a jar instead of an aar, the build system warns that it's unlikely to be a native library and may have unintended consequences at runtime.

Try to package that library as an .aar instead of a .jar. See this documentation: https://developer.android.com/studio/projects/android-library

Edit: Note that this file could not be loaded by the Android platform if it was included as is in the APK, so even though the previous build systems would allow you to put anything in an APK, the Android App Bundle is more restrictive to ensure that you don't accidentally put unnecessary files which would increase unnecessarily the size of your app.

Pierre
  • 15,865
  • 4
  • 36
  • 50
  • Thanks @Pierre, I have an app module which is compiling as a .jar file (because it's plain kotlin code in my case). I tried to compile it as a .aar file but I get the same error. Can it be an external dependency? How can I figure out which dependency is using this file? – Petermonteer Apr 02 '19 at 09:32
  • 1
    After a quick google search, I found this [post](https://stackoverflow.com/questions/21645071/using-gradle-to-find-dependency-tree) that explains how to list the dependencies from your app. You can then maybe look for something that contains "junixsocket" to see where that dependency comes from? – Pierre Apr 02 '19 at 13:59
  • I know how to list the dependencies from my app, I don't know how to search in the dependencies for the file that is causing me troubles, I will try that approach and get back – Petermonteer Apr 03 '19 at 10:38
  • Well better late than never ! I researched a little bit more, and what cracked it for me was using the apk analyzer on previously built apks. I'm using the openTok SDK that generates NDK files (.so files) and places them in sub directories for the various ABIs configuration, inside a lib folder. I've been trying to find a solution but couldn't find it yet. Any suggestions? @Pierre – Petermonteer Jun 17 '19 at 13:25
3

Ok it is working now! Steps I used to found the problem (thanks for pointing me in the right direction @Pierre)

Run a gradle build --scan from your terminal or go to the Gradle tab in Android Studio, select :app, help , androidDependencies to see your dependency graph.

Search the dependency graph for the library name related to the problem ( in my case I searched for socket, there was no match for libjunixsocket for example).

Going upwards on the dependency tree I realized it was caused by the 'io.voucherify.android.client:voucherify-android-sdk:2.1.0' dependency.

I just added @aar at the end of the dependency implementation, and I managed to build the app bundle.

implementation 'io.voucherify.android.client:voucherify-android-sdk:2.1.0@aar'
Petermonteer
  • 296
  • 4
  • 17