New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileTree() does not import the subdirectory #2394

Closed
Jehan opened this Issue Jul 5, 2017 · 10 comments

Comments

Projects
None yet
3 participants
@Jehan

Jehan commented Jul 5, 2017

Hello,

I may be completely misunderstanding things since I am new to Gradle, but I have a project with native libraries for Android, using most of Android Studio (2.3.3) default gradle.

  • I have all my libraries under app/libs/{ABI}/.
  • I added the following to the build.gradle of the app:
dependencies {
[… other stuff which were already here …]
    compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
}

task nativeLibsToJar(type: Zip) {
    destinationDir file("$buildDir/native-libs")
    baseName 'native-libs'
    extension 'jar'
    from fileTree(dir: 'libs', include: '**/*.so*')
    into 'lib/'
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn(nativeLibsToJar)
}
  • I have appropriate macros in the CMakeLists.txt for declaring the library dependencies of the wrapper library.

Expected Behavior

If keeping a simple case of only one level directory, it's all good: the app builds, links correctly to the libraries, and run without a problem.
Some of the libraries though have modules (in the form of other libraries, i.e. other .so files), which are usually in a subdirectory. I would like to keep this tree structure, and I was expecting the above code to respect this tree structure.
For instance, let's say, I have:

libs/armeabi/libbar.so
libs/armeabi/libfoo.so
libs/armeabi/libfoo-modules/module1.so
libs/armeabi/libfoo-modules/module2.so

I want this structure to be kept, and when the app run, it should be able to find the modules under lib/libfoo-modules/.

Current Behavior

Unfortunately, under Android, the APK only has:

lib/armeabi/libbar.so
lib/armeabi/libfoo.so

Anything in a subdirectory is gone.
If I check the jar file (unzip -l app/build/native-libs/native-libs.jar), it correctly contains the tree structure though, but not in the apk anymore (running unzip -l ./app/build/outputs/apk/app-debug.apk, only first level .so files are present).

Context

This is very annoying because the application needs to dynamically load these .so modules. Right now, it still works if I move all the .so files into a single-level lib/. The main libraries simply loop through all .so, and discards them which don't seem to fit their expected module contents. Still it's annoying because:
1/ since I have several libraries which use this concept, they both have to load several dozens of .so files even though 2/3 of these aren't for them.
2/ you never know, if something goes wrong; better to have a clean tree structure.

Steps to Reproduce (for bugs)

1/ create a tree structure:

app/libs/{ABI}/libfoo.so
app/libs/{ABI}/bla/bla.so

2/ Make them into a jar file and have this jar included as a dependency into your apk as proposed above.

3/ Check the content of the resulting APK (and inside the app's sandbox in Android). lib/{ABI}/libfoo.so will be there but not lib/{ABI}/bla/bla.so.

Your Environment

Android Studio 2.3.3
I am not sure of the details of gradle nor could I run a build scan since I don't know where the gradle binary is (I assume there is a binary somewhere installed by Android Studio since I didn't install it independently so it's not in my path, but I could not find it). My version of gradle would be whatever comes by default with Android Studio 2.3.3.

@bmuschko

This comment has been minimized.

Show comment
Hide comment
@bmuschko

bmuschko Jul 10, 2017

Contributor

You'll be able to achieve what you want with this code:

task nativeLibsToJar(type: Zip) {
    destinationDir file("$buildDir/native-libs")
    baseName 'native-libs'
    extension 'jar'
    from('libs') {
        include '**/*.so*'
    }
    into 'lib'
}
Contributor

bmuschko commented Jul 10, 2017

You'll be able to achieve what you want with this code:

task nativeLibsToJar(type: Zip) {
    destinationDir file("$buildDir/native-libs")
    baseName 'native-libs'
    extension 'jar'
    from('libs') {
        include '**/*.so*'
    }
    into 'lib'
}
@Jehan

This comment has been minimized.

Show comment
Hide comment
@Jehan

Jehan Jul 11, 2017

Hi,

Thanks, I'll try this later tonight. Does that mean that I misunderstood how the previous code was meant to work, or was it also supposed to work, and there is a bug?

Jehan commented Jul 11, 2017

Hi,

Thanks, I'll try this later tonight. Does that mean that I misunderstood how the previous code was meant to work, or was it also supposed to work, and there is a bug?

@Jehan

This comment has been minimized.

Show comment
Hide comment
@Jehan

Jehan Jul 11, 2017

So I just tested your code, and it doesn't work. To be more accurate, it does exactly the same thing as the previous code, which is that I can see the full tree (with subdirectories containing module .so files) in native-libs.jar but not in the apk. And as expected, I therefore get errors when running the application.

I don't understand why all the *.so files in subdirectories don't end up packaged. Any more ideas?

Jehan commented Jul 11, 2017

So I just tested your code, and it doesn't work. To be more accurate, it does exactly the same thing as the previous code, which is that I can see the full tree (with subdirectories containing module .so files) in native-libs.jar but not in the apk. And as expected, I therefore get errors when running the application.

I don't understand why all the *.so files in subdirectories don't end up packaged. Any more ideas?

@bmuschko

This comment has been minimized.

Show comment
Hide comment
@bmuschko

bmuschko Jul 13, 2017

Contributor

I would like to keep this tree structure, and I was expecting the above code to respect this tree structure.

I am confused. Didn't you say that you wanted to preserve the directory structure?

If this is a question about APKs then I think you are better off asking the question on the Google forum for the Gradle Android plugin.

Contributor

bmuschko commented Jul 13, 2017

I would like to keep this tree structure, and I was expecting the above code to respect this tree structure.

I am confused. Didn't you say that you wanted to preserve the directory structure?

If this is a question about APKs then I think you are better off asking the question on the Google forum for the Gradle Android plugin.

@Jehan

This comment has been minimized.

Show comment
Hide comment
@Jehan

Jehan Jul 13, 2017

I am confused. Didn't you say that you wanted to preserve the directory structure?

That's indeed what I want. If I have:

libs/armeabi/libfoo.so
libs/armeabi/libfoo-modules/bar.so

I want my app to find:

lib/libfoo.so
lib/libfoo-modules/bar.so

Right now, with the existing code, and the variant you proposed as well, it finds only:

lib/libfoo.so

And anything in a sub-directory seems to be simply discarded.

If this is a question about APKs then I think you are better off asking the question on the Google forum for the Gradle Android plugin.

Ok. I am new to both Gradle and Android. I assumed there might have been a Gradle issue since that was the build system but maybe the issue is on Android side. I will look for the forum you are talking about and ask there as well.

Jehan commented Jul 13, 2017

I am confused. Didn't you say that you wanted to preserve the directory structure?

That's indeed what I want. If I have:

libs/armeabi/libfoo.so
libs/armeabi/libfoo-modules/bar.so

I want my app to find:

lib/libfoo.so
lib/libfoo-modules/bar.so

Right now, with the existing code, and the variant you proposed as well, it finds only:

lib/libfoo.so

And anything in a sub-directory seems to be simply discarded.

If this is a question about APKs then I think you are better off asking the question on the Google forum for the Gradle Android plugin.

Ok. I am new to both Gradle and Android. I assumed there might have been a Gradle issue since that was the build system but maybe the issue is on Android side. I will look for the forum you are talking about and ask there as well.

@Jehan

This comment has been minimized.

Show comment
Hide comment
@Jehan

Jehan Jul 13, 2017

Google forum for the Gradle Android plugin.

I am a little lost. I was looking for this, and find a lot of places, but nothing which seems particularly official. Would you have a link?

Jehan commented Jul 13, 2017

Google forum for the Gradle Android plugin.

I am a little lost. I was looking for this, and find a lot of places, but nothing which seems particularly official. Would you have a link?

@bmuschko

This comment has been minimized.

Show comment
Hide comment
@bmuschko

bmuschko Jul 14, 2017

Contributor

I am sorry. I can't quite follow what files you expect in which directory. Can we get started by you setting up a sample repository on GitHub that reproduces the issue without applying the Android plugin? After that we can add Android to the mix.

I am a little lost. I was looking for this, and find a lot of places, but nothing which seems particularly official. Would you have a link?

Please open the issue here: https://code.google.com/p/android/issues

Contributor

bmuschko commented Jul 14, 2017

I am sorry. I can't quite follow what files you expect in which directory. Can we get started by you setting up a sample repository on GitHub that reproduces the issue without applying the Android plugin? After that we can add Android to the mix.

I am a little lost. I was looking for this, and find a lot of places, but nothing which seems particularly official. Would you have a link?

Please open the issue here: https://code.google.com/p/android/issues

@Jehan

This comment has been minimized.

Show comment
Hide comment
@Jehan

Jehan Jul 15, 2017

If you really don't understand, that's probably an Android issue. I'm not sure which is which since I use gradle through Android Studio in a very stupid way (i.e.: I click a button). For info, the Android issue: https://issuetracker.google.com/issues/63707864

I will see to make a sample repository with Gradle only depending on what I am answered on the Google bugtracker.

Jehan commented Jul 15, 2017

If you really don't understand, that's probably an Android issue. I'm not sure which is which since I use gradle through Android Studio in a very stupid way (i.e.: I click a button). For info, the Android issue: https://issuetracker.google.com/issues/63707864

I will see to make a sample repository with Gradle only depending on what I am answered on the Google bugtracker.

@bmuschko

This comment has been minimized.

Show comment
Hide comment
@bmuschko

bmuschko Jul 18, 2017

Contributor

Thanks for raising the issue on the Google forum. I am going to close this issue for now. Feel free to reopen if you need further assistance and can provide a sample project.

Contributor

bmuschko commented Jul 18, 2017

Thanks for raising the issue on the Google forum. I am going to close this issue for now. Feel free to reopen if you need further assistance and can provide a sample project.

@bmuschko bmuschko closed this Jul 18, 2017

@tapika

This comment has been minimized.

Show comment
Hide comment
@tapika

tapika May 13, 2018

I want to create sub-folders - but can you provide demo how it could be done ?
Method above does not seems to work.

You can post reply over here: https://stackoverflow.com/questions/50316372/android-gradle-how-to-include-shared-object-with-specific-folder-structure
if you want.

tapika commented May 13, 2018

I want to create sub-folders - but can you provide demo how it could be done ?
Method above does not seems to work.

You can post reply over here: https://stackoverflow.com/questions/50316372/android-gradle-how-to-include-shared-object-with-specific-folder-structure
if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment