Categories
Android React-Native

React Native App: Task :app:processDebugMainManifest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @379b3356

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

I had the same problem (JDK 16) and fixed it with:

cd android && gradlew clean
cd ..


npx react-native start

This will run the metro window
then open android studio and let it clean project
run app in android studio

Categories
Uncategorized

How to store access token securely in React Native

Async Storage#

Async Storage is a community-maintained module for React Native that provides an asynchronous, unencrypted, key-value store. Async Storage is not shared between apps: every app has its own sandbox environment and has no access to data from other apps.

DO USE ASYNC STORAGE WHEN…DON’T USE ASYNC STORAGE FOR…
Persisting non-sensitive data across app runsToken storage
Persisting Redux stateSecrets
Persisting GraphQL state
Storing global app-wide variables

Secure Storage#

React Native does not come bundled with any way of storing sensitive data. However, there are pre-existing solutions for Android and iOS platforms.

iOS – Keychain Services#

Keychain Services allows you to securely store small chunks of sensitive info for the user. This is an ideal place to store certificates, tokens, passwords, and any other sensitive information that doesn’t belong in Async Storage.

Android – Secure Shared Preferences#

Shared Preferences is the Android equivalent for a persistent key-value data store. Data in Shared Preferences is not encrypted by default, but Encrypted Shared Preferences wraps the Shared Preferences class for Android, and automatically encrypts keys and values.

Android – Keystore#

The Android Keystore system lets you store cryptographic keys in a container to make it more difficult to extract from the device.

In order to use iOS Keychain services or Android Secure Shared Preferences, you can either write a bridge yourself or use a library which wraps them for you and provides a unified API at your own risk. Some libraries to consider:

Ref: https://reactnative.dev/docs/security

Categories
React-Native

How to format ISO 8601 date to local date time in moment.js

As your getting date as String, so you need to convert it into Date then you can update formate as you want.

// YOUR_DATE_STRING = 2014-09-08T08:02:17-05:00

const utcDate = moment.utc(YOUR_DATE_STRING).toDate();
const localDate = moment(utcDate).local().format('YYYY-MM-DD HH:mm:ss');
Categories
Android React-Native

Change package name for Android in React Native

I’ve renamed the project’ subfolder from: “android/app/src/main/java/MY/APP/OLD_ID/” to: “android/app/src/main/java/MY/APP/NEW_ID/

Then manually switched the old and new package ids:

In: android/app/src/main/java/MY/APP/NEW_ID/MainActivity.java:

package MY.APP.NEW_ID;

In android/app/src/main/java/MY/APP/NEW_ID/MainApplication.java:

package MY.APP.NEW_ID;

In android/app/src/main/AndroidManifest.xml:

package="MY.APP.NEW_ID"

And in android/app/build.gradle:

applicationId "MY.APP.NEW_ID"

In android/app/BUCK:

android_build_config(
  package="MY.APP.NEW_ID"
)
android_resource(
  package="MY.APP.NEW_ID"
)

Gradle’ cleaning in the end (in /android folder):

./gradlew clean

Ref: https://stackoverflow.com/questions/37389905/change-package-name-for-android-in-react-native

Categories
Cocoapods

Install CocoaPod Version

Recently, I’ve created react native app with this command:

npx react-native init myapp

and I got these error: “Installing required CocoaPods dependencies”

info Installing required CocoaPods dependencies
(node:8874) UnhandledPromiseRejectionWarning: Error: Failed to install CocoaPods dependencies for iOS project, which is required by this template.
Please try again manually: "cd ./myapp/ios && pod install".

and “React requires CocoaPods version >= 1.10.1”

`React` requires CocoaPods version `>= 1.10.1`, which is not satisfied by your current version, `1.10.0`

Here is my solution:

  1. Check cocoapods version
pod --version
1.10.0

2. Cocoapods gem list

gem list cocoapods
*** LOCAL GEMS ***

cocoapods (1.10.0)
cocoapods-core (1.10.0)
cocoapods-deintegrate (1.0.4)
cocoapods-downloader (1.4.0)
cocoapods-plugins (1.0.0)
cocoapods-search (1.0.0)
cocoapods-trunk (1.5.0)
cocoapods-try (1.2.0)

3. Install cocoapods version

gem install cocoapods -v 1.10.1
Fetching cocoapods-1.10.1.gem
Fetching cocoapods-core-1.10.1.gem
Successfully installed cocoapods-core-1.10.1
Successfully installed cocoapods-1.10.1
Parsing documentation for cocoapods-core-1.10.1
Installing ri documentation for cocoapods-core-1.10.1
Parsing documentation for cocoapods-1.10.1
Installing ri documentation for cocoapods-1.10.1
Done installing documentation for cocoapods-core, cocoapods after 3 seconds
2 gems installed

4. Cocoapods install specific version in your project.

pod _1.10.1_ install
// pod _{version}_ install

** Don’t forget to put underscore before and after version number

This does not change the default CocoaPods version used when running pod install

I hope this help.

Ref: https://blog.echobind.com/managing-cocoapods-versions-across-projects-93cb2222f906