Skip to content
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

Error when building an Android Bundle #1117

Closed
slobglob opened this issue Dec 31, 2018 · 32 comments
Closed

Error when building an Android Bundle #1117

slobglob opened this issue Dec 31, 2018 · 32 comments

Comments

@slobglob
Copy link

Hey,

Trying to build an Android bundle and not APKs.
I get the following error:
File 'root/lib/arm64-v8a/include/opencv2/core/wimage.hpp' uses reserved file or directory name 'lib'.

I understand it's using a reserved bundle name probably, any idea how can it be fixed or when?

Thanks !

@saudet
Copy link
Member

saudet commented Dec 31, 2018

It looks like we'd need to create AAR files in addition to JAR files for this to work:
https://stackoverflow.com/questions/50279346/android-app-bundle-build-fails/50355398
It would add complexity to the build system and probably create hassle for users that are interested in portability to other platforms than Android... In any case, if you're interested in upgrading the build to support the creation of AAR files, please do, contributions are welcome!

@talregev
Copy link

I have the same issue.
I am Author of cv_bridge_javacv library,
and I use android javacv arm / arm64 versions.
Can you make AAR files only for android?

@saudet
Copy link
Member

saudet commented Apr 17, 2019

@talregev Yes, it's possible. Contributions are welcome!

@marwfair
Copy link

I'm running into a similar issue: File 'root/lib/arm64-v8a/ffmpeg' uses reserved file or directory name 'lib'. Has there been any updates to address this?

@saudet
Copy link
Member

saudet commented Nov 12, 2019

BTW, in case anyone is wondering, we can exclude those files from the build.
They are not necessary at runtime.

@akash2018xD
Copy link

akash2018xD commented Nov 12, 2019 via email

@saudet
Copy link
Member

saudet commented Nov 12, 2019

@akash2018xD There's some examples of that in issue #353.

@lisichka999
Copy link

@saudet Excluding file solved the problem, but what does this library do? Don't we need it at all? Thanks

@saudet
Copy link
Member

saudet commented Jan 22, 2020

@lisichka999 No, it should be made more modular, see issue #1071.

@phillies
Copy link

phillies commented Jun 25, 2020

I get a similar error:
File 'root/lib/x86_64/include/opencv2/shape/shape_distance.hpp' uses reserved file or directory name 'lib'.

with javacv included in my kotlin project

    implementation "org.bytedeco:javacv:1.5.3"
    implementation "org.bytedeco:opencv-platform:4.3.0-1.5.3"

But I'm unable to fix it by excluding the files as shown above. I tried the example given above

packagingOptions {
    pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
    pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'
    pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
    pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
}

Which obviously did not work because I use opencv-platform not javacpp-presets. So I adjusted the paths to what I think should be right

    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        pickFirst 'META-INF/maven/org.bytedeco/opencv-platform/pom.properties'
        pickFirst 'META-INF/maven/org.bytedeco/opencv-platform/pom.xml'
    }

But the error persists. Any ideas?

@saudet
Copy link
Member

saudet commented Aug 19, 2020

@phillies You'll need to exclude all the files from lib/x86_64/include, etc.

@vdang
Copy link

vdang commented Nov 21, 2020

@saudet How can we exclude all the files from lib/x86_64/include exactly? The link you provided above which you said to have some examples for exclusion seems to point to what @phillies had. I can't find any details on excluding .h files.

I tried exclude '**/lib/arm64-v8a/include/*' which didn't help. More specically:

android {
    ...
    packagingOptions {
        exclude '**/lib/arm64-v8a/include/*'
        pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
        pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
    }
}

dependencies {
    implementation "org.bytedeco:javacv:1.4.1"
    implementation "org.bytedeco.javacpp-presets:opencv:3.4.1-1.4.1"
    implementation "org.bytedeco.javacpp-presets:opencv:3.4.1-1.4.1:android-arm"
    implementation "org.bytedeco.javacpp-presets:opencv:3.4.1-1.4.1:android-arm64"
    implementation "org.bytedeco.javacpp-presets:opencv:3.4.1-1.4.1:android-x86"
    ...
}

(my error message was File 'root/lib/arm64-v8a/include/cvkernels.h' uses reserved file or directory name 'lib'. hence arm64-v8a in the path)

@saudet
Copy link
Member

saudet commented Nov 21, 2020

Something like this I guess: #1329 (comment)

@vdang
Copy link

vdang commented Nov 21, 2020

Thanks for the super quick response, @saudet!

Neither exclude 'META-INF/native-image/**' nor exclude 'META-INF/**/root/lib/arm64-v8a/include/cvkernels.h' worked for me unfortunately. I still get the exact same error message: File 'root/lib/arm64-v8a/include/cvkernels.h' uses reserved file or directory name 'lib'.

Any other advice?

@rgm-22
Copy link

rgm-22 commented Jul 15, 2021

I'm running into a similar issue: File 'root/lib/arm64-v8a/ffmpeg' uses reserved file or directory name 'lib'. Has there been any updates to address this?

Same problem. Did you solved it @marwfair?

@saudet
Copy link
Member

saudet commented Jul 16, 2021

It looks like we need to move those files from /root/lib into /lib instead:
https://developer.android.com/guide/app-bundle/app-bundle-format
I'm not sure how to do that, they are already under /lib in the JAR files. For some reason the tool that you are using to create bundles moves them under /root instead, so if you figure out why it's doing that, fixing that should make it work.

@rgm-22
Copy link

rgm-22 commented Jul 19, 2021

Thank you for your quick comment Samuel!

I succeed💪. I was placing the ffmpeg-android-arm.jar, ffmpeg-android-arm64.jar, ffmpeg-android-x86.jar, and ffmpeg-android-x86_64.jar in the app/libs path instead of placing the image .so files in jniLibs/arm64-v8a and jniLibs/arm64-v7a.

Thank you again for your work! 😊

@yasserakbbach
Copy link

yasserakbbach commented Sep 22, 2021

Hello @rgm-22 I'm having the same issue:

Execution failed for task ':app:packageReleaseBundle'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.PackageBundleTask$BundleToolWorkAction
   > File 'root/lib/commons-codec-1.8.jar' uses reserved file or directory name 'lib'.

Could you please provide me with more details to solve the problem?

@rgm-22
Copy link

rgm-22 commented Sep 22, 2021

Hi @yasserakbbach!

Be careful where you are placing this "commons-codec-1.8.jar".

You need to follow this file structure:

  • app/libs -> place the ".jar" libraries

  • app/src/main/jniLibs -> place the compiled libraries (".so" files) following the arm64-v8a, armeabi, armeabi-v7a, etc. structure.

I hope to help!

@yasserakbbach
Copy link

Hi @rgm-22 again,
Thanks for your input, I've just solved the problem by deleting the following dependencies (they were unused anyways)

implementation 'commons-codec:commons-codec:1.10'
implementation 'com.google.guava:guava:28.0-android'
implementation 'org.apache.directory.studio:org.apache.commons.codec:1.8'

@rgm-22
Copy link

rgm-22 commented Sep 23, 2021

Hi @yasserakbbach!

I'm glad you succeed 💪😀.

@chandresh9191
Copy link

Thank you @rgm-22

@lakharasachin-qf
Copy link

Hii @rgm-22
I am using FFMPEG and placed complied FFMPEG into resourse/lib/ folder and it's totally working fine in debug mode, But when I am creating release bundle it shows error
"File 'root/lib/arm64-v8a/ffmpeg' uses reserved file or directory name 'lib'."

Capture
Capture2

Please help me how can resolve this problem

@rgm-22
Copy link

rgm-22 commented Nov 6, 2021

Hi @lakharasachin-qf !

Sorry for the late response.

Please, try to follow this structure:

  • app/libs -> place the ".jar" libraries

  • app/src/main/jniLibs -> place the compiled libraries (".so" files) following the arm64-v8a, armeabi, armeabi-v7a, etc. structure.

00

01

02

I hope to help!

@hamorillo
Copy link

Hi @rgm-22!

I'm adding the libraries under app/libs:
Screenshot 2021-11-23 at 10 28 45

Adding on build.gradle the following:
Screenshot 2021-11-23 at 10 29 50

The APK generation works but when I try to generate a bundle for uploading to the Google Play console I always obtain the same error:

A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade File 'root/lib/arm64-v8a/include/opencv2/imgcodecs/imgcodecs.hpp' uses reserved file or directory name 'lib'.

Any idea?

@rgm-22
Copy link

rgm-22 commented Nov 27, 2021

Hi @hamorillo!

In my case, I didn't add the "-android-arm.jar" "-android-arm64.jar" files in app/libs nither build.gradle.

Remeber to add the compiled libraries (".so" files) to app/src/main/jniLibs, following the arm64-v8a, armeabi, armeabi-v7a, etc. structure.

Please, let me know your results.
I know that this process is frustrating when your app is ready to be uploaded to Google Play ☹

I hope to help!

@saudet
Copy link
Member

saudet commented Nov 30, 2021

After investigating this thoroughly, it appears that the cleanest solution to this issue is to get Gradle to extract the libraries for us, then tell the plugin for Android to pick them up from that location, and let it do whatever it wants with them. Something like the following in app/build.gradle works fine for me:

configurations {
    javacpp
}

task javacppExtract(type: Copy) {
    dependsOn configurations.javacpp

    from { configurations.javacpp.collect { zipTree(it) } }
    include "lib/**"
    into "$buildDir/javacpp/"
    android.sourceSets.main.jniLibs.srcDirs += ["$buildDir/javacpp/lib/"]

    tasks.getByName('preBuild').dependsOn javacppExtract
}

dependencies {
    implementation group: 'org.bytedeco', name: 'javacv', version: '1.5.6'
    javacpp group: 'org.bytedeco', name: 'openblas-platform', version: '0.3.17-1.5.6'
    javacpp group: 'org.bytedeco', name: 'opencv-platform', version: '4.5.3-1.5.6'
    javacpp group: 'org.bytedeco', name: 'ffmpeg-platform', version: '4.4-1.5.6'
    ...
}

To shorten that a bit further, it should be feasible to add this "javacppExtract" task to Gradle JavaCPP, but I'm not sure it's worth the trouble. If that snippet works well enough for everyone here, I may just add that to the docs somewhere. What do you all think?

@saudet
Copy link
Member

saudet commented Dec 2, 2021

I've added that code snippet in commit bytedeco/gradle-javacpp@036a685 and also updated the JavaCV-android-example sample project in commit bytedeco/sample-projects@2378afc, so I think I'll consider this issue solved. If anyone still has any problems with that though, please let me know!

@saudet saudet closed this as completed Dec 2, 2021
@NguyenNguyen77
Copy link

Hi All,
I have the same issue, but my issue does not relate to the lib.
I want to build aab to upload CH Play but it always fails and shows a message:
File 'root/res/drawable-hdpi/ic_launcher.png' uses reserved file or directory name 'res'.

I tried to search ic_launcher.png but my app does not use that name. I don't know how to resolve it.
Please help me resolve this issue. I research for 2 days but was still stuck with it.
Thanks.

@hilmisatrio16
Copy link

hilmisatrio16 commented May 8, 2024

Hi all,
I have the same problem when build bundle on android studio

Error:

Execution failed for task ':app:packageDebugBundle'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.PackageBundleTask$BundleToolWorkAction
   > File 'root/lib/arm64-v8a/include/cvkernels.h' uses reserved file or directory name 'lib'.

Dependecy

    implementation 'org.bytedeco:javacv:1.4.4'
    implementation 'org.bytedeco.javacpp-presets:opencv:4.0.1-1.4.4:android-arm64'
    implementation 'org.bytedeco.javacpp-presets:opencv:4.0.1-1.4.4:android-arm'
    implementation 'org.bytedeco.javacpp-presets:opencv:4.0.1-1.4.4:android-x86

I still don't understand how to solve it, thanks.

@GerritPotgieter
Copy link

Hi all, I have the same problem when build bundle on android studio

Error:

Execution failed for task ':app:packageDebugBundle'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.PackageBundleTask$BundleToolWorkAction
   > File 'root/lib/arm64-v8a/include/cvkernels.h' uses reserved file or directory name 'lib'.

Dependecy

    implementation 'org.bytedeco:javacv:1.4.4'
    implementation 'org.bytedeco.javacpp-presets:opencv:4.0.1-1.4.4:android-arm64'
    implementation 'org.bytedeco.javacpp-presets:opencv:4.0.1-1.4.4:android-arm'
    implementation 'org.bytedeco.javacpp-presets:opencv:4.0.1-1.4.4:android-x86

I still don't understand how to solve it, thanks.

Im getting this same error still aswell and I'm unsure if this issue is resolvable still, I've been trying to just manually exclude all the libraries but it takes quite a while

@saudet
Copy link
Member

saudet commented Sep 9, 2024

Please try to follow the instructions here:
https://github.com/bytedeco/gradle-javacpp?tab=readme-ov-file#the-platform-plugin

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

No branches or pull requests