NPM Package Manager on Android? - android

So I need a module. Using the old trick of (https://registry.npmjs.org/) I can download a single module, but that module has a dependency module which can have more on them. Its tedious. I can't use Termux (I have android 6) Is there any way to install npm package manager on android? I already have NodeJS Front End for Android, but I can't do new things without new modules. Any console with npm would work... Or an script to download npm modules and dependency's on node would work too...

Download https://registry.npmjs.org/npm/-/npm-8.5.0.tgz
Untar npm-8.5.0.tgz to a local directory, e.g. /storage/emulated/0/
Move to npm-8.5.0 and create directory cache
Now open NodeJS Frontend
Press +, set title and browse to an empty directory the-package-dir except for a node_modules subdirectory.
Set environment variable:
npm_config_cache=/storage/emulated/0/npm-8.5.0/cache
Path to js file:
/storage/emulated/0/npm-8.5.0/package/bin/npm-cli.js
js file cli options:
install --omit=dev --omit=optional --omit=peer --no-bin-links --ignore-scripts --no-audit --no-fund the-package
save and run
Now the-package installed in directory the-package-dir

Related

Build Failing for React Native iOS, "Multiple commands produce" Error

We were working on a react native project. One of my team members added some native modules on Linux and linked android. By then I am trying to link things in iOS but the build is always failing with this kind of error trace. The Android project is building normally.
I deleted xyz.xcworkspace and Podfile.lock then tried pod install.
Also, I tried to delete my node_modules and then yarn install followed by yarn link.
react-native-cli: 2.0.1
react-native: 0.61.4
yarn 1.19.1
Pod 1.8.4
XCode Version 11.2.1 (11B500)
macOS Catalina 10.15.1 (19B88)
xyz warning
duplicate output file '/Users/user/Library/Developer/Xcode/DerivedData/xyz-hhesslamjsqmbobykhskliclusph/Build/Products/Debug-iphonesimulator/xyz.app/AntDesign.ttf' on task: PhaseScriptExecution [CP] Copy Pods Resources /Users/faisal/Library/Developer/Xcode/DerivedData/xyz-hhesslamjsqmbobykhskliclusph/Build/Intermediates.noindex/xyz.build/Debug-iphonesimulator/xyz.build/Script-47F818C57EEC47EA3303EA1B.sh
xyz workspace errors
Multiple commands produce '/Users/user/Library/Developer/Xcode/DerivedData/xyz-hhesslamjsqmbobykhskliclusph/Build/Products/Debug-iphonesimulator/xyz.app/Zocial.ttf':
1) Target 'xyz' (project 'xyz') has copy command from '/Users/user/Desktop/xyz/native/node_modules/react-native-vector-icons/Fonts/Zocial.ttf' to '/Users/user/Library/Developer/Xcode/DerivedData/xyz-hhesslamjsqmbobykhskliclusph/Build/Products/Debug-iphonesimulator/xyz.app/Zocial.ttf'
2) That command depends on command in Target 'xyz' (project 'xyz'): script phase “[CP] Copy Pods Resources”
There are multiple errors and warnings like this but have same format with different file names.
The problem is you have duplicate resources due to RN auto-linking.
To fix this
Click Your Xcode project Name on project files
Navigate to Build Phases tab
Scroll down to Copy Bundle Resources drop down to expand
Scroll down to Copy Pod Resources and compare the duplicates with the ones on Copy Bundle Resources
Delete the duplicates on Copy Bundle Resources not on Copy Pod Resources
Rebuild your project.
Also refer to this issue
The problem seems to be caused by the new autolinking feature in React Native 0.60 - the line use_native_modules! in ios/Podfile means when you do pod install, any pods found in node_modules are automatically linked. This means that links to all font files are added to [CP] Copy Pods Resources when you do pod install.
Please see this image.
Open Your iOS project in Xcode.
Then follow these steps in the image.
You will see input Files and output files under Copy Pod Resource. Remove the duplicate ones listed here from the above list in Copy Bundle Resources.
Run react-native run-ios
For the xCode 11+ and react-native 0.60+,
The answer is copied from this GitHub issue answer
The problem seems to be caused by the new autolinking feature in
React Native 0.60 - the line use_native_modules! in ios/Podfile
means when you do pod install, any pods found in node_modules are
automatically linked. This means that links to all font files are
added to [CP] Copy Pods Resources when you do pod install.
If you previously installed react-native-vector-icons manually by
adding the font files to Copy Bundle Resources, you then get a
"Multiple commands produce..." fatal build error.
So to fix the problem, just remove the font files from Copy Bundle
Resources, so that they are only in [CP] Copy Pods Resources.
So the official documentation on the repository of the library is outdated and does not mention it. You should follow installation steps up to adding the fonts list to info.plist, and DO NOT create Fonts folder-group and copy-paste the fonts into that folder.
You need to delete this manually from Copy Bundle resource.
Else You need to change build setting to build using legacy build.
You will find the Copy Bundle resource under build phases.
I am able to solve the issue by following this step.
All you have to do is open your project folder -> go to /ios and open file YourProjectName.xcodeproj then follow this https://lifesaver.codes/answer/error-multiple-commands-produce-in-xcode-10, then you just need to delete all fonts there and run npx react-native run-ios

How do I add media codecs support to Crosswalk while using the Cordova plug-in?

I'm building a PhoneGap app which needs to play AAC audio. It works well using the native WebView, but I would like to use Crosswalk on a build targeting APIs 16-20 because some CSS features in my app do not work at all on Android 4.x.
When I make a copy of the project to add Crosswalk Lite, I can see that the app works except for the <audio> element pointing to a AAC file. This is because Crosswalk does not ship with proprietary codecs by default.
The linked page says:
To build Crosswalk with these codecs, a developer must run the build
with the “must accept a EULA” switch turned on:
$ xwalk/gyp_xwalk -Dmediacodecs_EULA=1
Then build Crosswalk. The ffmpegsumo.dll or libffmpegsumo.so in
the build output directory will contain the proprietary codecs.
Refer to Crosswalk Build Instruction for more details.
However, I am adding Crosswalk using the suggested plug-in, thus I get pre-built libraries without proprietary codecs:
phonegap plugin add cordova-plugin-crosswalk-webview --variable XWALK_MODE="lite" --save
How can I integrate proprietary codecs in the Cordova Crosswalk plug-in?
I managed to understand the (convoluted) process of building everything. This answer deals with the process of compiling a custom build of the full Crosswalk (not the lite version).
Actually, I decided to finally use the standard build and replace AAC audio with MP3s, but I thought this answer could be useful for future reference.
Environment
I compiled Crosswalk in a Ubuntu 16.04 Docker container to avoid "polluting" my system and to ensure I had the right Linux version. The standard image is pretty barebones so I installed some dependencies. I also set up a shared folder to access the compiled files:
docker run -it -v /home/andrea/shared:/shared ubuntu:16.04 /bin/bash
apt update
apt install -y python git nano lsb-release sudo wget curl software-properties-common
export EDITOR=nano # life it too short to learn vi
Finally, it is necessary to add the multiverse repositories:
apt-add-repository multiverse
Note: this procedure needs a lot of space. Make sure to have at least 25GB of free space before continuing.
Requirements
Install the depot_tools as outlined in the documentation:
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=$PATH:/path/to/depot_tools
Initialize a working directory with:
mkdir crosswalk-checkout
cd crosswalk-checkout
export XWALK_OS_ANDROID=1
gclient config --name src/xwalk https://github.com/crosswalk-project/crosswalk.git
Then edit the config file with nano .gclient and add the following line:
target_os = ['android']
Save the file.
Fetching the source
Attempt a first sync with:
gclient sync
This command will fail but it's OK. The instructions say:
Do not worry if gyp_xwalk fails due to missing dependencies; installing them is covered in a later section, after which you can run gyp_xwalk manually again.
Adjust the install-build-deps.sh file and then run it:
sed -si "s/msttcorefonts/ttf-mscorefonts-installer/g" src/build/install-build-deps.sh
sudo ./src/build/install-build-deps-android.sh
Run gclient sync again and wait until it finishes correctly.
Building
By inspecting the files src/xwalk/build/common.gypi and src/tools/mb/mb_config.pyl, we can see that we need to add ffmpeg_branding="Chrome" in the build arguments.
To prevent an error later on, install the development package related to libnotify:
sudo apt install libnotify-dev
Move to the src directory and open the configuration:
cd src/
gn args out/Default
Ensure the content is as follows:
import("//xwalk/build/android.gni")
target_os = "android"
is_debug = false
ffmpeg_branding = "Chrome"
use_sysroot = false
The parameters use_sysroot = false prevents yet another error. When saving the file, you should see something like this:
Waiting for editor on "/home/utente/crosswalk-checkout/src/out/Default/args.gn"...
Generating files...
Done. Wrote 6060 targets from 1003 files in 2416ms
Issue cd .. and run gclient sync again.
Finally, to build the core library do:
cd src/
ninja -C out/Default xwalk_core_library
This will build the library for ARM, producing an AAR file located at:
src/out/Default/xwalk_core_library.aar
Copy this file in a safe place.
Building for x86
Get back to the args with:
gn args out/Default
Add the following line:
target_cpu = "x86"
Save the file, run gclient sync again and then repeat the ninja command. Make a copy of the new AAR file which now contains the x86 libraries.
Using the AAR files
The standard Cordova Crosswalk plug-in uses a single AAR file with libraries for both platforms. This message by Raphael Kubo da Costa suggests how to produce this single archive:
AAR files are just zip files; given the only difference between the ARM
and x86 AAR files are the different shared libraries, you can use
something like zipmerge or anything that merges zip files (or even
extract everything into some directory and then create one new zip file)
to build one final, multi-architecture AAR archive.
Finally, to use the custom built AAR file in the Cordova plug-in, see How to change the Crosswalk version used by the Cordova Crosswalk Webview plugin.

Cordova 3.5 embedded webview with plugins

I have an existing native Android app to which I'm adding a cordova webview.
This is in the new gradle project format with Intellij.
I've successfully gotten the cordova activity loaded, and opens as expected.
I added the webview by following the cordova docs.
Now I'd like to use some of the plugins available but can't find a way to add them to the project.
Since this isn't a cordova generated project, plugman doesn't work. I've tried copying the JS and Java files for the plugins I'm interested in to my source dir but that results in various errors.
e.g. require is undefined, when this happened, I added requirejs to the webview's index.html
and it moved on to
Uncaught Error: Module name "cordova/exec" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded cordova.js:8
Failed to load resource file:///android_asset/www/scripts/cordova_plugins.js
deviceready has not fired after 5 seconds. cordova.js:1191
Channel not fired: onDOMContentLoaded
How do I get a plugin working with this?
EDIT:
I am manually moving stuff around.
This has to be put into an existing project which uses gradle for building.
Using cordova create generates a project in the old ANT format.
I followed the docs on embedding a WebView in an existing project (see the link above), but it doesn't mention any of the JavaScript files. So I just copied cordova.js from the android platform directory.
Like wise, I download the plugins I wanted, copied their JavaScript files, added the feature to build.xml and copied their Java files to my src directory.
I didn't know about cordova_plugins.js or that cordova prepare generates them.
You have to use Plugman to manage your plugins in the custom built Cordova WebView.
Please remove all your existing plugins and read them using plugman.
plugman install --platform android --project <proj> --plugin org.apache.cordova.battery-status --www <proj>/assets/www/scripts
where the <proj> is the folder where you main project is created,
Alternatively you could use --www parameter which allows you to specify where root of web application is stored. Example:
plugman install --platform android --project <proj> --plugin org.apache.cordova.battery-status --www <proj>/assets/www/scripts
Plugman reference
EDIT
If you have highly customized project, you could create empty Cordova project where you add
plugins, and copy cordova_plugins.js from this project to assets\www\scripts, Cordova should pickup these files. If you have your plugins JS files not in the assets\www\scripts\plugins\ folder, but instead of that in assets\www\plugins you have to modify content of cordova_plugins.js like that
module.exports = [
.....
{
"file": "../plugins/org.apache.cordova.inappbrowser/www/InAppBrowser.js",
"id": "org.apache.cordova.inappbrowser.InAppBrowser",
"clobbers": [
"window.open"
]
},
...
]
Here is some input on how I came though,
I am in a similar position like the OP, embedding a Cordova Web View in my Native Android Application.
After executing
plugman install --platform android --project <proj> --plugin org.apache.cordova.battery-status --www <proj>/assets/www/scripts
What happens is you get a new 'Cordova' folder in your original 'main' Folder, (Where your AndroidManifest.xml is). Besides that, there is the 'src' folder with the code you actually need generated.
What I did, was copying the org folder from src to the 'java' folder. And everything worked.

Cordova - Ignore folders on build

I've got a simple app for Phonegap. In the www folder I added some NPM sugar to help development. Now, during the build I'd like to ignore this node_module folder created by NPM when it loads the dependencies. It actually make the build fail.
I've added an ant.properties file within root/platforms/android/ and wrote this line:
aapt.ignore.assets:!.svn:!.git:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~:<dir>node_*
It prints that it ignores the folder node_modules because of that property, but when I look at the folder root/platforms/android/assets/www I can see the node_modules folder.
I guess my question is, is the folder actually being ignored in the created APK?
Make a copy of your APK and change the file extension from .apk to .zip then extract the zip. You will be able to browse to the www folder and see if it's in there or not.

Appcelerator titanium push Notification using C2DM?

I am using Appcelerator Titanium Version 1.8.0 have anyone tried push notification using google's C2DM.if so help me to create Sample push notification.
It is not that difficult: Here is steps for it...
Clone project from github
Find build.properties
Modify all paths to fit the paths (and versions) in your environment
Optionally you need to download and install the android sdk from here http://developer.android.com/sdk/ndk/index.html
Open console in module root and type ant and hit enter
The build process should end with something like build successfully
In the module directory, you will find the build result in the dist folder
Open that folder, unzip the com.findlaw.c2dm-android-0.1.zip
A folder is created: modules/android/com.findlaw.c2dm/0.1
copy the content of modules/android/com.findlaw.c2dm/0.1 to the folder [your_project]/modules/android/com.findlaw.c2dm/
Copy timodule.xml to the root folder of your project (where the tiapp.xml is located)
Open tiapp.xml and replace all occurences of com.findlaw.c2dm with your app id, except of the line including this:
com.findlaw.c2dm.C2DMReceiver
Register the module in tiapp.xml:
<modules>
<module platform="android" version="0.1">com.findlaw.c2dm</module>
</modules>
14. Use the module in your code as described in the example of the module
For more check this communication of our team member...
Your Module folder should not inside the Resource folder

Categories

Resources