Tag Archive for: Bash

CordovaError: Requirements check failed for JDK 1.8 or greater

If you have a Cordova Error after updating to Ubuntu 18.04, the easiest way to resolve this issue is removing openjdk-11 and reinstalling openjdk-8.

sudo apt purge openjdk-11-jdk-headless openjdk-11-jre-headless
sudo apt install openjdk-8-jdk

There is not support for the new java versions yet in Cordova/Android (at the post date)

Simple local development environment for web apps

  1. Open your app working directory
    • There you should have at least index.html
  2. Launch http-server in your terminal
    • If you haven’t installed it yet: npm install http-server -g
  3. Launch chromium-browser --disable-web-security --user-data-dir=/tmp/something in your terminal to allow all origins (temporary ignore  CORS mechanism )
    • Make sure you don’t have other instances open: pkill -f chromium
  4. Type in the address bar one of the address from your http-server info to access to your app

Note: Use Chromium without security just with your own code for testing and development, do not browse with it and beware about using third-party software in your code.

Create a multilingual React website

First of all create a react app ready to go

create-react-app MY-WEBSITE

This will create a react app with everything configured.

npm start

Add i18next package

npm i -S i18next

This will let us do our website/app internationalization.

Set up your I18next file

Create a i18n.js file in the src folder with this code:

import i18n from 'i18next';

i18n
  .init({
    fallbackLng: 'en',
    lng: navigator.language.split('-')[0],
    debug: true,
    resources: {
      en: {
        translation: {
          "Hola": "Hello",
          "Adiós": "Bye"
        }
      }
    }
  });

export default i18n;

Finally, indicate which text you want to translate

Import your i18n.js and use its t function to indicate where it should be the internationalization.

import React, { Component } from 'react';
import logo from './logo.svg';
import i18n from './i18n';
import './App.css';

let t = i18n.t.bind(i18n);

class App extends Component {
  render() {
    return (
      <div className="App">
        <div className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h2>{t("Hola")}</h2>
        </div>
        <p className="App-intro">
          To get started, edit <code>src/App.js</code> and save to reload.
        </p>
      </div>
    );
  }
}

export default App;

 

Dealing with keystores and passwords when building for Android with Cordova

Which is the easiest way of builing apps in Android with Cordova?

Use a build.json file

{
     "android": {
         "release": {
             "keystore": "./your_keystore_file",
             "storePassword": "your_keystore_password",
             "alias": "your_alias_name",
             "password" : "your_alias_password"
         }
     }
 }

And type in your console: cordova build android –release

If you already have a keystore and don’t know what alias to use, run the command: keytool -list -v -keystore YOUR_KEYSTORE_FILE to see all the available aliases.

Keystore only has one password. You can change it using keytool: keytool -storepasswd -keystore MY_KEYSTORE

Note: I’m locating my build.json and keystore_file in my project’s root folder.

My Bash Prompt customization

14:34 gengns@mycomputer  Desktop$ ▮

Open a console in your HOME folder and type vim .bashrc, then copy the next line at the end of the file:

PS1='\[\e[30;47m\]\A \u@\h \W\[\e[0m\]$ '
  • \[\e[30;47m\] # 30 is black foreground color and 47 is light grey background
  • \A # hour in hh:mm format
  • \u # user name
  • \h # host name
  • \W  # working folder name
  • \[\e[0m\] # reset

More info: customization and colors in Bash