Moodle Mobile 3.7.0 - android

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.

Related

Trying to build an Ionic 4 app for Android but gradle, paths and variables aren't found even though I've already set them

everyone. I want to build an app for one of my clients. It's the first time I develop an app on Ionic 4 and at the time of building the apk, I couldn't do it.
I checked all the errors that the console prompted to me. At first, it seemed to be moving on, however, at a moment, the console prompted the following:
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=/Users/Cris/Library/Android/sdk (DEPRECATED)
Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
[ERROR] An error occurred while running subprocess cordova.
cordova build android --release exited with exit code 1.
I have already done a research about this topic, and even though there are similar questions here on this website, I couldn't find any answer that solved my problem.
I have already defined the ANDROID_SDK_ROOT, the ANDROID_HOME and GRADLE_HOME. I checked all of those dirs to see if they worked, and they did so. I have already downloaded and set up the JDK variable and path as well.
I have installed Android Studio with the version of sdk API that I need for this development. Also, when I researched about gradle, I installed it with npm and manually (without counting the time it got installed automatically with Android Studio). HOWEVER!!! The console tells that gradle isn't installed, that Android paths aren't set or that they are deprecated (both options, actually), and that I have to do what I have already done several times.
Here I let you see the variables set:
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=${JAVA_HOME}/bin:$PATH
export ANDROID_HOME=/Users/Cris/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export GRADLE_HOME=/Users/Cris/Library/Gradle.0/bin
export PATH=$PATH:$GRADLE_HOME
export ANDROID_SDK_ROOT=$ANDROID_HOME
export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin
Do you guys have any idea of how to proceed? Thank you before hand
GRADLE_HOME should be the root folder of the <gradle installation folder>, currently its pointing to <gradle installation folder>/bin it should look like following
export GRADLE_HOME=/Users/Cris/Library/Gradle.0
I have already overcame the problem with the following instructions:
When you want to build your app for Android with Ionic 4 on MAC, install Java (JDK), install Android Studio, install the API version you want to work with, install Homebrew (on its website there is a so easy-to-follow guide to install it) and install Gradle by writing the following command:
brew install gradle
Then, write the following command and copy the route of the gradle directory:
brew info gradle
Go to Ionic Framework Developer Resources for MAC
And follow the instructions to set up the paths. Don't forget to check if the example paths work just fine on your computer by doing it as the following example:
ls /Users/your-user/Library/gradle-5.4
If the "echo" of that line says that the directory exists, then it's okay and you must set that path the way it is. If the directory doesn't exists (as it'll happen in the case of the $GRADLE_HOME's path, you should paste the route that you copied some steps ago.
To corroborate that those paths exist on your MAC, besids saving them on your MAC's ~/.bash_profile, enter them one by one (exporting the variable and exporting its path) inside the MAC's terminal.
Then, as one of the last steps (I'm not going to describe how to sign your app, because it's explained on the link above), write on a console opened inside your project the following line:
sudo ionic cordova build android --prod
It's going to build your app for production, which releases you from signing your app in order to install it on your mobile device
IMPORTANT NOTE:
If you want to sign your app, you should run the following command before signing it (it replaces the last command I wrote above):
sudo ionic cordova build --release android
You can find more information about releasing your app without a signed key and how to sign it on this website's section:
Publishing Your App - Ionic Framework
Thank you for checking this answer out! :D

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

Failed to build apk via Gradle

I'm trying to build apk from my Ionic project via gradle but it shows the following error:-
Note: I've tried the following solutions which didn't work for me:-
1) Removed nodejs, clear all directories related to nodejs, cordova, ionic, gradle and do fresh installation.
2) Change distribution url in graddle-wrapper.properties file in project folder to distributionUrl=https://services.gradle.org/distributions/gradle-1.12-all.zip and build again.
3) Installed ant4windows and executed $ rm -r ~/.gradle and hoping that ant will do the magic.
4) Downloaded gradle-2.12-bin.zip & replaced the 'gradle 2.2.1 zip' file in PC-User/.gradle/.. folder . but it still fetches gradle 2.2.1 zip & shows exception
Some days ago I successfully created my apk following https://www.youtube.com/watch?v=qVOwGyQB3DQ & the apk was built using ant. Also tell why gradle is taking over the ant this time?

How do I put my cordova application on the android play store?

If there is official cordova documentation for this, I couldn't find it and would appreciate a link. I have run cordova run android to deploy to my phone. Things look good. Now I'm ready to turn this into an official app that users can download on the android play store? When I build my app it generates a file named "CordovaApp-debug.apk". That "debug" part makes me think this is the wrong file to work with, but I'm not sure how to generate the right file.
Deploying a hybrid app to the Google Play Store
These steps would work for Cordova, PhoneGap or Ionic. The only difference would be, wherever a call to cordova is placed, replace it with phonegap or ionic, for your particular scenario.
Once you are done with the development and are ready to deploy, follow these steps:
Open a command line window (Terminal on macOS and Linux OR Command Prompt on Windows).
Head over to the /path/to/your/project/, which we would refer to as the Project Root.
While at the project root, remove the "Console" plugin from your set of plugins.The command is: cordova plugin rm cordova-plugin-console
While still at the project root, use the cordova build command to create an APK for release distribution.The command is: cordova build --release android
The above process creates a file called android-release-unsigned.apk in the folder ProjectRoot/platforms/android/build/outputs/apk/
Sign and align the APK using the instructions at https://developer.android.com/studio/publish/app-signing.html#signing-manuallyAt the end of this step the APK which you get can be uploaded to the Play Store.
Note: As a newbie or a beginner, the last step may be a bit confusing as it was to me. One may run into a few issues and may have some questions as to what these commands are and where to find them.
Q1. What are jarsigner and keytool?
Ans: The Android App Signing instructions do tell you specifically what jarsigner and keytool are all about BUT it doesn't tell you where to find them if you run into a 'command not found error' on the command line window.
Thus, if you've got the Java Development Kit(JDK) added to your PATH variable, simply running the commands as in the Guide would work. BUT, if you don't have it in your PATH, you can always access them from the bin folder of your JDK installation.
Q2. Where is zipalign?
Ans: There is a high probability to not find the zipalign command and receive the 'command not found error'. You'd probably be googling zipalign and where to find it?
The zipalign utility is present within the Android SDK installation folder. On macOS, the default location is at, user-name/Library/Android/sdk/. If you head over to the folder you would find a bunch of other folders like docs, platform-tools, build-tools, tools, add-ons...
Open the build-tools folder. cd build-tools. In here, there would be a number of folders which are versioned according to the build tool-chain you are using in the Android SDK Manager. ZipAlign is available in each of these folders. I personally go for the folder with the latest version on it. Open Any.
On macOS or Linux you may have to use ./zipalign rather than simply typing in zipalign as the documentation mentions. On Windows, zipalign is good enough.

Build android release apk on Phonegap 3.x CLI

How can I build an android app locally using the Phonegap 3.x CLI, ready to release? I check the bin folder generated inside the platforms/android directory of the project, and only has .debug APKs.
By the way, I use this command: phonegap local build android
This is for Phonegap 3.0.x to 3.3.x. For PhoneGap 3.4.0 and higher see below.
Found part of the answer here, at Phonegap documentation. The full process is the following:
Open a command line window, and go to /path/to/your/project/platforms/android/cordova.
Run build --release. This creates an unsigned release APK at /path/to/your/project/platforms/android/bin folder, called YourAppName-release-unsigned.apk.
Sign and align the APK using the instructions at android developer official docs.
Thanks to #LaurieClark for the link (http://iphonedevlog.wordpress.com/2013/08/16/using-phonegap-3-0-cli-on-mac-osx-10-to-build-ios-and-android-projects/), and the blogger who post it, because it put me on the track.
In PhoneGap 3.4.0 you can call:
cordova build android --release
If you have set up the 'ant.properties' file in 'platforms/android' directory like the following:
key.store=/Path/to/KeyStore/myapp-release-key.keystore
key.alias=myapp
Then you will be prompted for your keystore password and the output file (myapp-release.apk) ends up in the 'platforms/android/ant-build' directory already signed and aligned and ready to deploy.
In cordova 6.2.0
cd cordova/ #change to root cordova folder
platforms/android/cordova/clean #clean if you want
cordova build android --release -- --keystore="/path/to/keystore" --storePassword=password --alias=alias_name #password will be prompted if you have any
Previous answer:
According to cordova 5.0.0
{
"android": {
"release": {
"keystore": "app-release-key.keystore",
"alias": "alias_name"
}
}
}
and run ./build --release --buildConfig build.json from directory platforms/android/cordova/
keystore file location is relative to platforms/android/cordova/, so in above configuration .keystore file and build.json are in same directory.
keytool -genkey -v -keystore app-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
Following up to #steven-anderson
you can also configure passwords inside the ant.properties, so the process can be fully automated
so if you put in platform\android\ant.properties the following
key.store=../../yourCertificate.jks
key.store.password=notSoSecretPassword
key.alias=userAlias
key.alias.password=notSoSecretPassword
just wondered around a lot because I got the same issue but in my installation the command "cordova" was never available and "phone gap build android --release" just ignored the platform/android/ant.properties.
so looking inside my platform filter I found a folder named "cordova" and inside of it there was an "build" binary that accepted the --release argument, it asked me for the key chains and I ended with a signed and ready for production APK.
this was never documented in any part of the phone gap site and frankly speaking now I kinda hate phonegap :( it was supposed to make the things easier but everything was just complicated :(
Building PhoneGap Android app for deployment to the Google Play Store
These steps would work for Cordova, PhoneGap or Ionic. The only difference would be, wherever a call to cordova is placed, replace it with phonegap or ionic, for your particular scenario.
Once you are done with the development and are ready to deploy, follow these steps:
Open a command line window (Terminal on macOS and Linux OR Command Prompt on Windows).
Head over to the /path/to/your/project/, which we would refer to as the Project Root.
While at the project root, remove the "Console" plugin from your set of plugins.The command is: cordova plugin rm cordova-plugin-console
While still at the project root, use the cordova build command to create an APK for release distribution.The command is: cordova build --release android
The above process creates a file called android-release-unsigned.apk in the folder ProjectRoot/platforms/android/build/outputs/apk/
Sign and align the APK using the instructions at https://developer.android.com/studio/publish/app-signing.html#signing-manuallyAt the end of this step the APK which you get can be uploaded to the Play Store.
Note: As a newbie or a beginner, the last step may be a bit confusing as it was to me. One may run into a few issues and may have some questions as to what these commands are and where to find them.
Q1. What are jarsigner and keytool?
Ans: The Android App Signing instructions do tell you specifically what jarsigner and keytool are all about BUT it doesn't tell you where to find them if you run into a 'command not found error' on the command line window.
Thus, if you've got the Java Development Kit(JDK) added to your PATH variable, simply running the commands as in the Guide would work. BUT, if you don't have it in your PATH, you can always access them from the bin folder of your JDK installation.
Q2. Where is zipalign?
Ans: There is a high probability to not find the zipalign command and receive the 'command not found error'. You'd probably be googling zipalign and where to find it?
The zipalign utility is present within the Android SDK installation folder. On macOS, the default location is at, user-name/Library/Android/sdk/. If you head over to the folder you would find a bunch of other folders like docs, platform-tools, build-tools, tools, add-ons...
Open the build-tools folder. cd build-tools. In here, there would be a number of folders which are versioned according to the build tool-chain you are using in the Android SDK Manager. ZipAlign is available in each of these folders. I personally go for the folder with the latest version on it. Open Any.
On macOS or Linux you may have to use ./zipalign rather than simply typing in zipalign as the documentation mentions. On Windows, zipalign is good enough.
i got this to work by copy pasting the signed app in the same dir as zipalign. It seems that aapt.exe could not find the source file even when given the path. i.e.
this did not work
zipalign -f -v 4 C:...\CordovaApp-release-unsigned.apk C:...\destination.apk
it reached aapt.exeCordovaApp-release-unsigned.apk , froze and upon hitting return
'aapt.exeCordovaApp-release-unsigned.apk' is not recognized as an internal or external command, operable program or batch file.
And this did
zipalign -f -v 4 CordovaApp-release-unsigned.apk myappname.apk
I know this question asks about Phonegap 3.X specifically, but just for reference any Phonegap version above 4.0.0 uses Gradle instead of Ant to build by default. To use Ant instead of Gradle you can add this to your config.xml:
<preference name="android-build-tool" value="ant" />
When using Gradle the keystore signing information now needs to go into a new location (as outlined in this post). Create new file called 'release-signing.properties' in the same folder as "build.gradle" file and put inside the following content:
storeFile=..\\..\\some-keystore.keystore
storeType=jks
keyAlias=some-key
// if you don't want to enter the password at every build, you can store it with this
keyPassword=your-key-password
storePassword=your-store-password
You could try this command, it should build and run the app (so .apk should be created) :
phonegap local run android

Categories

Resources