Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up fully offline Cordova build?

I have created a test project in Cordova using cordova create hello com.example.hello HelloWorld ; cd hello ; cordova platform add android.

The first time I build it with cordova build, it downloads Gradle, and then what I think is a bunch of Maven files, almost 200 of them. These seem to be installed into ~/.gradle but I'm not sure that is the only place. Sample output:

$ cordova build
ANDROID_HOME=/opt/android
JAVA_HOME=/usr/lib/jvm/java-8-oracle/
Subproject Path: CordovaLib
Downloading https://services.gradle.org/distributions/gradle-3.3-all.zip
...............
Unzipping /home/ubuntu/.gradle/wrapper/dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9/gradle-3.3-all.zip to /home/ubuntu/.gradle/wrapper/dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9
Set executable permissions for: /home/ubuntu/.gradle/wrapper/dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9/gradle-3.3/bin/gradle
Starting a Gradle Daemon (subsequent builds will be faster)
Download https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom
Download https://jcenter.bintray.com/com/android/tools/build/gradle-core/2.2.3/gradle-core-2.2.3.pom
Download https://jcenter.bintray.com/com/android/tools/build/builder/2.2.3/builder-2.2.3.pom
Download https://jcenter.bintray.com/com/android/tools/lint/lint/25.2.3/lint-25.2.3.pom
(skip about 180 more lines here)
Download https://repo1.maven.org/maven2/junit/junit/3.8.1/junit-3.8.1.jar
Download https://repo1.maven.org/maven2/nekohtml/xercesMinimal/1.9.6.2/xercesMinimal-1.9.6.2.jar
Download https://repo1.maven.org/maven2/nekohtml/nekohtml/1.9.6.2/nekohtml-1.9.6.2.jar
The JavaCompile.setDependencyCacheDir() method has been deprecated and is scheduled to be removed in Gradle 4.0.
Incremental java compilation is an incubating feature.
The TaskInputs.source(Object) method has been deprecated and is scheduled to be removed in Gradle 4.0. Please use TaskInputs.file(Object).skipWhenEmpty() instead.
:preBuild UP-TO-DATE
(build continues normally here)

Now, this may be convenient, but absolutely not desirable from the perspective of having a reproducible build environment.

How do I set up Cordova to do fully offline builds? Would it do offline builds after the first one, or does it still check for (eg) Gradle updates?

How (and where) do I pre-install everything that cordova build looks for? Is there a way to get Cordova to install everything as a separate step from doing a build, and to do a build as a separate step from doing this install?

Can I archive the contents of ~/.gradle/ once, and then unpack it before doing a build (either on the same machine or a different one) and have that build run offline? How do I move ~/.gradle/ to (for example) a subdirectory of the Cordova project?

This is on a clean install of Ubuntu 16.04, with node and npm installed from nodesource. Versions:

$ cordova --version
7.0.1
$ npm --version
3.10.10
$ node --version
v6.10.3
like image 934
Alex I Avatar asked Nov 08 '22 21:11

Alex I


1 Answers

Sounds tricky. One possibility that comes to my mind: you could use a docker image with android and cordova already installed on your machine without internet. You will find many open-source images like this one: docker-cordova when searching for e.g. "cordova docker image".

like image 76
David Avatar answered Nov 14 '22 20:11

David