Hot questions for Using Ubuntu in cordova

Question:

After upgrading the cordova and the npm of my machine (Ubuntu 15.10) I can not build a new project with the cordova. The build accuses an error in graddle. I did some research and found some possible solutions. Solutions like changing the version and url graddle repo. Anyway, it did not work. I am using the cordova 6.0.0 and npm 1.4.21. Below commands of fresh cordova app installation:

soufraz@atlantis:~/Projects/apps$ cordova create test com.somename.test Test
Creating a new cordova project.
soufraz@atlantis:~/Projects/apps$ cd test/
soufraz@atlantis:~/Projects/apps/test$ cordova platform add android
Adding android project...
Creating Cordova project for the Android platform:
    Path: platforms/android
    Package: com.somename.test
    Name: Test
    Activity: MainActivity
    Android target: android-23
Android project created with cordova-android@5.1.0
Discovered plugin "cordova-plugin-whitelist" in config.xml. Installing to the project
Fetching plugin "cordova-plugin-whitelist@1" via npm
Installing "cordova-plugin-whitelist" for android

               This plugin is only applicable for versions of cordova-android greater than 4.0. If you have a previous platform version, you do *not* need this plugin since the whitelist will be built in.

soufraz@atlantis:~/Projects/apps/test$ cordova build
ANDROID_HOME=/home/soufraz/Install/android-sdk-linux
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:1.5.0.
     Required by:
         :android:unspecified
      > Failure initializing default system SSL context

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

BUILD FAILED

Total time: 0.769 secs
ERROR building one of the platforms: Error code 1 for command: /home/soufraz/Projects/apps/test/platforms/android/gradlew with args: cdvBuildDebug,-b,/home/soufraz/Projects/apps/test/platforms/android/build.gradle,-Dorg.gradle.daemon=true,-Pandroid.useDeprecatedNdk=true
You may not have the required environment or OS to build this project
Error: Error code 1 for command: /home/soufraz/Projects/apps/test/platforms/android/gradlew with args: cdvBuildDebug,-b,/home/soufraz/Projects/apps/test/platforms/android/build.gradle,-Dorg.gradle.daemon=true,-Pandroid.useDeprecatedNdk=true

Extra informations: - I have all android apis 19 - 24 installed. - cordova build android -- --ant doesn't works too - I've tested it with the java jdk 1.7 and 1.8 - All tries with --stacktrace/--debug/--info: pastebin.com/nD6GNkbR

check_reqs (it was asked via comments):

soufraz@atlantis:~/Projects/apps/test/platforms/android/cordova$ ./check_reqs 
ANDROID_HOME=/home/soufraz/Install/android-sdk-linux
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
Looks like your environment fully supports cordova-android development!

java -version:

openjdk version "1.8.0_66-internal"
OpenJDK Runtime Environment (build 1.8.0_66-internal-b17)
OpenJDK 64-Bit Server VM (build 25.66-b17, mixed mode)

Answer:

After nearly two weeks looking for a solution, I found a glorious question WITH A REAL ANSWER that solved the problem!!

Source: Peer not authenticated while importing Gradle project in eclipse

REPLICATING THE ORIGINAL ANSWER If you get any other error like this:

 Could not GET 'https://some_server.com/some/path/some.pom'.
     > peer not authenticated

Then you need to import a certificate:

keytool -import -alias <the short name of the server> -file <cert_file_name_you_exported.cer> -keystore cacerts -storepass changeit

It will prompt you to import the certificate, type yes and press enter.

Then restart your eclipse and try building the project.

Question:

I use the JDK in my NetBeans Java webservice by just pointing the directory where I've downloaded it to the project on NetBeans. Cant I do the same to build my Ionic APK? I tried setting the JAVA_HOME inside .bashrc with this line

export JAVA_HOME=$HOME/Apps/jdk1.8.0_144

But it didnt work, I dont get any return from java -version in terminal.


Answer:

Not only the JAVA_HOME environment variable should be set, but also JDK binaries should be on your PATH:

JAVA_HOME=$HOME/Apps/jdk1.8.0_144
export JAVA_HOME
export PATH="${JAVA_HOME}/bin:${PATH}"

Question:

When I run ````cordova run android``` in the path of my project I get

Android Studio project detected
cordova-android-support-gradle-release: Android platform: V7+
cordova-android-support-gradle-release: Wrote custom version '27.+' to /path/to/platforms/android/app/build.gradle
cordova-android-support-gradle-release: Wrote custom version '27.+' to /path/to/cordova-android-support-gradle-release/norsan-cordova-android-support-gradle-release.gradle
ANDROID_HOME=/usr/lib/android-sdk
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
Requirements check failed for JDK 1.8 or greater

My version of Java

$ java --version
openjdk 11.0.5 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-0ubuntu1.119.04)
OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-0ubuntu1.119.04, mixed mode, sharing)

My version of javac

$ javac --version
javac 11.0.5

My version of Cordova

$ cordova --version
9.0.0 (cordova-lib@9.0.1)

My version of Node

$ node --version
v10.15.2

My version of Nodejs

$ nodejs --version
v10.15.2

My version of NPM

$ npm --version
5.8.0

My version of Gradle

$ gradle -version
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/usr/share/java/groovy-all.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

------------------------------------------------------------
Gradle 4.4.1
------------------------------------------------------------

Build time:   2012-12-21 00:00:00 UTC
Revision:     none

Groovy:       2.4.16
Ant:          Apache Ant(TM) version 1.10.5 compiled on March 28 2019
JVM:          11.0.5 (Private Build 11.0.5+10-post-Ubuntu-0ubuntu1.119.04)
OS:           Linux 5.0.0-38-generic amd64

I found that android-studio --version didn't do anything but silently wait, but when I open the program through the graphical user interface I see that the version is 3.6.1.

My version of androidsdk is Unknown... Not sure why.

$ androidsdk --version
SDK_ROOT=/home/galen/snap/androidsdk/21/AndroidSDK
Picked up _JAVA_OPTIONS: -Duser.home=/home/galen/snap/androidsdk/21
Unknown version

My version of Ubuntu

$ cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=19.04
DISTRIB_CODENAME=disco
DISTRIB_DESCRIPTION="Ubuntu 19.04"
NAME="Ubuntu"
VERSION="19.04 (Disco Dingo)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 19.04"
VERSION_ID="19.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=disco
UBUNTU_CODENAME=disco

My understanding is that Java 11 comes later than JDK 1.8, so why does the requirements check fail? And, how do I fix this requirements check failure?


Answer:

You are correct that Java 11 is more recent than JDK 1.8 and that it should work in theory.

However, cordova explicitly requires JDK 1.8 still:

Android doesn’t use oracles java but their own implementation, which at the moment is like java 8. So this is an android limitation, not something cordova can fix.

(cf. also issue 510)

Their development guide explicitly mentions JDK 1.8 as well:

Java Development Kit (JDK)

Install Java Development Kit (JDK) 8.

So the fix for now would be installing JDK 1.8 (if you go for Oracle note their recently changed license terms). You may watch PR 928 that attempts to ease that restriction, though.

Question:

I was trying to run an ionic app on my Android devices, while having installed all requirements: Android SDK, OpenJDK (open-source version of Oracle's Java Developer Kit), added ANDROID_HOME and JAVA_HOME to my environment variables (in my case ~/.profile) and pluged my phone through USB.

Output java -version:

openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build
1.8.0_131-8u131-b11-2ubuntu1.17.04.3-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

Output javac -version:

javac 1.8.0_131

Parts of ~/.profile: (my container for environment variables)

# Android
export ANDROID_HOME="$HOME/Programme/Android"
export PATH="$ANDROID_HOME/tools:$PATH"
export PATH="$ANDROID_HOME/platform-tools:$PATH"

# JAVA
export JAVA_HOME="/usr/lib/jvm/default-java"
export PATH="$JAVA_HOME:$PATH"

Output adb devices:

List of devices attached
TA364*****  device

Even having set everything up, the command ionic cordova run android does not work and throws that error message:

Error: Requirements check failed for JDK 1.8 or greater

How to get it running?


Answer:

The clue is to add the /bin folder also to your path. Type that into your ~/.profile:

export PATH="$JAVA_HOME/bin:$PATH"

If you have installed more than one Java version, you will have to ensure that you selected the right one corresponding to your path inside JAVA_HOME:

sudo update-alternatives --config java

This will give you a menu for activating that version which suits your necessities most.