How to set up fully offline Cordova build? - android

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

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".

Related

Jenkins cannot create cordova platforms

I have a jenkins job that is supposed to create a cordova app but it's failing some reason that I can't quite identify. The jenkins job simply does this:
cordova platform add android
cordova prepare android
cordova build android --debug --verbose
The first command (cordova platform add android) is resulting in the following error:
ENOENT: no such file or directory, mkdir 'platforms/android/app/src/main'
Error: ENOENT: no such file or directory, mkdir 'platforms/android/app/src/main'
at Object.mkdirSync (fs.js:738:3)
at Object.module.exports.makeDirSync (/Users/me/Documents/Jenkins/sharedspace/apps/my-app/cordova/node_modules/fs-extra/lib/mkdirs/make-dir.js:23:13)
at /Users/me/Documents/Jenkins/sharedspace/apps/my-app/cordova/node_modules/cordova-android/lib/create.js:231:16
+ /Users/me/.nvm/versions/node/v16.13.2/bin/cordova prepare android
(node:23901) ExperimentalWarning: The fs.promises API is experimental
Discovered platform "android". Adding it to the project
EEXIST: file already exists, mkdir '/Users/me/Documents/Jenkins/sharedspace/apps/my-app/cordova/platforms'
+ /Users/me/.nvm/versions/node/v16.13.2/bin/cordova build android --debug --verbose
(node:23902) ExperimentalWarning: The fs.promises API is experimental
No platforms added to this project. Please use `cordova platform add <platform>`.
CordovaError: No platforms added to this project. Please use `cordova platform add <platform>`.
at Object.preProcessOptions (/Users/me/.nvm/versions/node/v16.13.2/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/util.js:275:15)
at /Users/me/.nvm/versions/node/v16.13.2/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/build.js:29:31
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
at startup (internal/bootstrap/node.js:236:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:560:3)
Build step 'Execute shell' marked build as failure
When I look inside the platforms directory on the jenkins box it is empty. It is able to create the platforms folder itself, just nothing else under. It doesn't seem to be a permission issue as far as I can tell. If I ssh into the box as the same user that jenkins in using I can run the cordova commands fine and everything works.
Furthermore, if I add the platform manually by sshing into the box and then let jenkins take over after the android folder already exists, the job works fine. So I guess for some reason it's not able to add the android project.
If it helps, this is what cordova requirements gives:
cordova requirements
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-30,android-29,android-28
Gradle: installed /usr/local/Cellar/gradle/7.3.3/bin/gradle
Okay, I finally figured this SOB out! After taking a few weeks off and coming back to this I noticed that there is a setting in the job config called "Shared Workspace" and I had it set to the value (). I don't know what that means, but it had the effect of putting the code for this project in the
/Users/me/Documents/Jenkins/sharedspace
folder, which apparently was causing problems with cordova. Once I set the Shared Workspace value to NONE, it moved the project to the
/Users/trident/Documents/Jenkins/workspace/my-app
folder which is more what I would expect. After that, lo and behold, everything works.

Run / Build Apk is not updated with the latest changes

I have a problem in my vuejs + cordova project, when there is an edit file for example (login.vue) the changes only appear when running the 'npm run serve' command but when running the command 'cordova run browser / android' the login.vue file is not updated. I've tried clear cache 'npm clear cache' and 'cordova clean / cordova prepare' the results are still the same.
Command Before run/build cordova :
npm run serve
npm run build
cd cordova_app
cordova run/build android or browser
it is because the latest changes you made to files need to be brought to the platform folder (E.g. $projectroot/platform/android/www).
For this you have two options:
you can edit the file here directly
$projectroot/platform/$platform_name/www, but as a result, if you delete the platform, then that change will get lost.
Or you can make also make the changes in $projectroot/www/ but you will need to run few commands: cordova platform remove android and cordova platform add android if it is for Android. Please note that this will also overwrite any special configuration you have made in your IDE (xCode for iOS or Android Studio for Android) because it regenerates from your code, a new workspace for your app to be compiled, including your latest code, all in the platform folder.
Good luck!

Could not compile settings gradle React Native

The app worked for me from another machine, now that downloading the files from the repository on another computer gives me this problem
FAILURE: Build failed with an exception.
Where:
Settings file 'C:\Users\samue\Desktop\MCGPS\TeachAll\android\settings.gradle'
What went wrong:
Could not compile settings file 'C:\Users\samue\Desktop\MCGPS\TeachAll\android\settings.gradle'.
startup failed:
General error during semantic analysis: Unsupported class file major version 57
This is an issue with how Gradle is automating the build and the current version of the JDK installed on your machine, follow these steps to fix it, the react native documentation states you need adoptopenjdk8, however you may have other conflicting JDK versions in the same directory.
Blog post: https://ashirazee.medium.com/react-native-android-failure-build-failed-with-an-exception-908934c3a32b
Step one:
open up your terminal and navigate to /Library/Java/JavaVirtualMachines by typing the following command:
cd /Library/Java/JavaVirtualMachines
after you have done that type ls to see what files are included and take note of the versions.
incase you have one or multiple JDK files present like such:
adoptopenjdk-8.jdk jdk-16.jdk jdk-8.jdk
then go head and delete them with the following command line :
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-16.jdk
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-8.jdk
the only dependency you need is adoptopenjdk-8.jdk as mentioned in the react native docs
however delete that aswell and reinstall it after you have completed these steps:
sudo rm -rf /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk
after you have done so you can check if the files still exist by typing ls
if the files are deleted.
Step 2:
then run the following commands to insure all other links, plugins and files are deleted as-well from your Library:
run the following :
sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -rf ~/Library/Application\ Support/Oracle/Java
Step 3:
once you have done the following, reinstall the correct jdk as mentioned in the react native docs like so:
brew install --cask adoptopenjdk/openjdk/adoptopenjdk8
https://reactnative.dev/docs/_getting-started-macos-android
this may say adoptopenjdk-8.jdk is already installed, but go ahead and reinstall install it with:
brew reinstall adoptopenjdk8
At this point the error should be resolved and your build should work.
It is important to note that this is a build error, since react native uses Gradle to build automations, the conflicting of multiple jdk versions can cause your build to fail.
please refer to the following documentation:
https://docs.gradle.org/current/userguide/userguide.html
This is due to the jdk version intalled on your system.
If you're using the latest version of Java Development Kit, you'll need to change the Gradle version of your project so it can recognize the JDK. You can do that by going to {project root folder}\android\gradle\wrapper\gradle-wrapper.properties and changing the distributionUrl value to upgrade the Gradle version. You can check out latest releases of gradle and note the latest version of gradle and edit in gradle-wrapper.properties and change the distributionUrl
I have solved issue by just opening project in Android studio
react native version 0.60.5
Open the android folder using Android Studio. Then all dependencies will start downloading(as shown in the picture). Let them complete. After completely downloaded and loaded you can run the project.
this issue seems to be with the java version, pls check for correct version. also even if two or more jdk are installed we can specify during runtime which jdk has to be used by specifying this gradlew.bat build -Dorg.gradle.java.home=---path-to-jdk---
Solved it by downgrading Java and upgrading Gradle version.
I had the same problem, I came here looking for a solution. I selected JDK 11 instead of 16, but it didn't work, I remembered that I didn't point the way for the new JDK version in ~/.bashrc, now it finally worked.

Moodle Mobile 3.7.0

After downloading Moodle Mobile2 from github at https://github.com/moodlehq/moodlemobile2 so now its a zip file on my computer. In simple steps how do i get to publish this on googleplay?
I have tried renaming the zipfile to .apk then used advanced apktool to sign and recompile but when uploading to google play i get:-
Upload failed
Your APK cannot be analyzed using aapt. Error output:
Failed to run aapt dump badging:
ERROR: dump failed because no AndroidManifest.xml found
Obviously things are not so simple. If someone can help me with some basic steps from zip file to apk and publish i would be grateful as i am trying to self learn the process but need some help.
Thanks guys
It is definitely not so simple as to download the repository :) The detailed steps (from 1 to 9) are listed in the official documentation here: https://docs.moodle.org/dev/Setting_up_your_development_environment_for_Moodle_Mobile_2
Summarizing the documentation and from my own experience you need to:
Install all building tools dependencies, at the time I'm writing this (Aug '19) those are: node v8.12.x or v11.12.x, cordova 8.1.2, ionic, gulp
Install additional tools for MacOSX or Windows if you are using any of those SOs (see doc page linked above).
Clone the repository with git clone or unzip it after downloading the zipped repository
To prepare the iOS and Android platforms (that allows you to build the binaries later on) go inside your project folder (unzipped or cloned folder) and run (from a terminal):
$ npm install
$ cordova prepare
$ gulp
Resolve any compatibility issues among packages that may have arised.
Apply the npm packages fixes to build for production with AOT listed in step 9 of the documentation page I linked above.
Build the apk from the terminal:
$ npm run ionic:build -- --prod
$ cordova build android --release
At this point you will have the compiled apk ready to be signed and uploaded to the Google Store.

Meteor Crosswalk build fails at second 'ant debug' step

I have a Meteor Cordova Android app which I'm trying to migrate and build using Crosswalk. I followed the steps from here:
https://meteor.hackpad.com/Building-Meteor-app-with-Crosswalk-kHKh4DzGxFQ
Until here, the build succeeds.
android update project --subprojects --path . --target "android-19"
ant debug
cd ..
ant clean
The next step, ant release or ant debug, the build fails with 100 javac errors. The error log is very close to whats mentioned here: https://github.com/meteor/meteor/issues/3076
The solution partly is here:
https://github.com/RayHuo/MyXwalk/wiki/MIGRATE-AN-EXISTING-CORDOVA-APPLICATION-TO-CROSSWALK-WITH-CORDOVA-3.4-OR-LATER.
Its says:
"And the solution is to changing the second ant debug to cordova build android"
But the android project folder is generated by Meteor and not Cordova, so I do not have cordova executable installed to run a cordova build android.
I still tried installing cordova separately and building it, but it simply says, 'its not a cordova based project'.
How do we do the last step using Meteor? There is another option to build it using Eclipse/ADT, but I want to figure this out within the Meteor build process.
I know I'm missing something simple here. Any help is greatly appreciated!
Thanks.
crosswalk provides a HelloWorld cordova/example via the bin/create
utility on the intel crosswalk website.
that CordovaLib directory can replace the meteor equivalent
,however the latest meteor version fails, so there maybe some
crosswalk/meteor version problems now to resolve.
HelloWorld appears to work with old version 8 crosswalk
and new meteor build
https://crosswalk-project.org/documentation/cordova/develop_an_application.html
Meteor 1.2 now supports CrossWalk with $ meteor add crosswalk

Categories

Resources