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

Node module folders starting with underscore not copied on Android #60

Closed
antoniuschan99 opened this issue Apr 2, 2018 · 9 comments
Closed

Comments

@antoniuschan99
Copy link

antoniuschan99 commented Apr 2, 2018

  • Version: 7.10.0
  • Platform: x86_64

I am able to get iOS working for a project but have much trouble getting Android working.
It successfully builds, but it seems to not be able to read a file in node_modules which causes the app to crash after launch. The files are there in node_modules too. It seems to have to do with the _generated_ folder?

Here is the log in logcat

Node assets copy failed at com.janeasystems.rn_nodejs_mobile.RNNodeJsMobileModule$1.run(RNNodeJsMobileModule.java:86) at java.lang.Thread.run(Thread.java:764) Caused by: java.io.FileNotFoundException: nodejs-project/node_modules/node-opcua-service-read/_generated_/_auto_generated_ReadValueId.js

@antoniuschan99
Copy link
Author

antoniuschan99 commented Apr 2, 2018

I received a reply from @jaimecbernardo in the Gitter chat

Hi @antoniuschan99 , Thank you for reporting it and opening the issue. The aapt (Android Asset Packaging Tool) seems to ignore any folders starting with an underscore, so they end up not being copied to the APK. It must be the <dir>_* entry in its source: https://android.googlesource.com/platform/frameworks/base/+/b41af58f49d371cedf041443d20a1893f7f6c840/tools/aapt/AaptAssets.cpp#60

There must be a way to define a different ignore pattern for your Android project, and figuring it out is on our list of TODOs. In the meanwhile, I hope this was helpful and please let us know if you find a solution and if you're on react-native, cordova or pluginless scenario.

@jaimecbernardo jaimecbernardo changed the title Node assets copy failed Node module folders starting with underscore not copied on Android Apr 2, 2018
@jaimecbernardo
Copy link
Member

I'll add the workaround that was found for @antoniuschan99 case here. If someone knows of a better/distinct solution that could possibly be made to work just from the plugin, we'd appreciate if you could leave a comment. Thank you, in advance.

As a workaround for the react-native plugin, it's possible to get the paths starting with underscore to be included in the APK, by overriding the Android Asset Packaging Tool ignore pattern for both the react-native application and the plugin, by adding the following:

        aaptOptions {
            ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
        }

inside android { / defaultConfig { in two gradle files inside your react-native project folder android/app/build.gradle and node_modules/nodejs-mobile-react-native/android/build.gradle.

The files have similar structures that look something like this:

...
android {
    ...
    defaultConfig {
        ...
        aaptOptions {
            ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
        }
    }
...
}

It may be necessary to do a proper gradle clean after these changes before running the application. From the react-native project folder, run:

cd android
./gradlew clean
cd ..
react-native run-android

This workaround isn't a permanent solution for the plugin. While one of the gradle files involved in the workaround is inside the plugin, the application gradle file is created by react-native, so we'll still have to look for a more permanent solution that doesn't involve editing that file manually.

@antoniuschan99
Copy link
Author

confirmed this fixes it :)

@luandro
Copy link

luandro commented Apr 14, 2018

Just wanted to leave noted here the pattern suggested by @jaimecbernardo that worked for me to get scuttlebot working:

...
android {
    ...
    defaultConfig {
        ...
        aaptOptions {
            ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~'
        }
    }
...
}

@jaimecbernardo
Copy link
Member

In @luandro 's case ( #60 (comment) ), he had issues with directories starting with underscore (<dir>_*) and files starting with dot (.*), so he removed both these patterns from the default ignoreAssetsPattern.

  • Default from aapt: '!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~'
  • Correct for his case: '!.svn:!.git:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~'

The correct pattern to use depends on the files that are causing issues.

@Matthcw
Copy link

Matthcw commented Jun 29, 2019

I confirm that this issue still is the case in 2019, however the workaround still works! Thanks!

@magalhas
Copy link

magalhas commented Oct 2, 2020

This stills happens at of now (2020). It would be nice to include the fix, having to manually change build.gradle file inside node_modules is not friendly at all. @jaimecbernardo

@viniciuscb
Copy link

I am having to make this fix inside node_modules in 2023.

@lypanov
Copy link

lypanov commented Aug 16, 2024

Still required in 2024 to make use of the openai library. Alas couldn't get it working as the gradle files have changed format apparently so rolled my own openai api.

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

7 participants