How to build a release version of react-native Examples - android

Now, I can install debug version of react-native examples on my Phone.
follow these steps:
./gradlew :Examples:UIExplorer:android:app:installDebug
./packager/packager.sh
But I have to start the server for the app to run correctly.
I want to bundle the js-bundle file to apk and install a release version on my phone.
And I can demonstrate it to my friends anywhere.
Can anybody help me?
Thank you in advance for your kind help or some hints.

First, you need to sign your apk file and add a release build type to your gradle config following the instructions in the documentation
Then, run you packager with ./packager/packager.sh or simply npm start.
The next step is to download the js bundle to the android assets directory. Because there is no react.gradle file this needs to be done manually - source:
curl "http://localhost:8081/Examples/UIExplorer/UIExplorerApp.android.bundle?platform=android&dev=false" -o "Examples/UIExplorer/android/app/src/main/assets/UIExplorerApp.android.bundle"
Finally, you can run the installRelease gradle task (or assembleRelease and then install the apk manually).

Update on pianiel's answer: The curl command is now
curl "http://localhost:8081/Examples/UIExplorer/js/UIExplorerApp.android.bundle?platform=android&dev=false" -o "Examples/UIExplorer/android/app/src/main/assets/UIExplorerApp.android.bundle"
because of changes made to UIExplorer's project structure.

Related

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.

How to install app on android with gradlew.sh?

I have downloaded an android app from Github (Link). But I am unable to install this app on android (I am using Linux). Could someone tell me which direction should I go?
App folder Contains following files:
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle
first install gradle this linke
then you can build the project on Command Line './gradlew assembleDebug'
This creates an APK named module_name-debug.apk in project_name/module_name/build/outputs/apk/. The file is already signed with the debug key and aligned with zipalign, so you can immediately install it on a device.

Meteor cordova build - how to deploy to device?

I have been reading https://meteor.hackpad.com/Getting-Started-With-Cordova-Z5n6zkVB1xq#:h=Device-Setup and the docs on how to deploy a cordova app are a bit lacking, as to be expected with very new functionality! I execute: meteor build <bundle path> -p <host>:<port> which has built my app, I have a tarball for the server and an /android folder which contains an AndroidManifest.xml and all sorts of other files - I assume I need to compile this into an APK.
Is this correct? Can someone point me in the right direction? Thanks!
Inside "bundle path"/android you will find you apks already compiled.

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

How to compile APK from command line?

I am interested in making Android apps on demand. Depending on the clients request, my web site would send me a JSON file direct to a Windows application that I have created in Delphi. This one would save the file inside the Android app source folder and then, execute a command line telling the Android compiler to generate the APK file and send it to my client, all that without my presence.
The Android project was made with MotoDev. And it uses the Android SDK that is in my root.
How should I configure the command line to achieve this from inside my Delphi program?
I will also need to change the manifest to put a new version number so it does not conflict with other clients version.
Android uses the Ant build system, so you can create a build.xml and build.properties file for your project.
You'll need to create the build.xml file first though:
android update project -p .
This will generate a build.xml file. You should probably customize the build steps and targets for your project. A good idea in your case would be to have the build.properties file generated by your website for the specific build... Then include it via the build.xml file. In particular, you will need to specify in the build.properties file where the signing keys are, and what the password is:
Build.Properties:
key.store=keystore.dat
key.alias=signing_key
key.store.password=password123
key.alias.password=password123
The build process using ant also allows you to do variable replacements in Java files, which might be another idea. It would allow you to customize the build process further on a client by client basis.
By default, the build is triggered by:
ant clean
ant release
Another neat idea: Have Ant copy the resulting APK file to a network share accessible by the website by placing a < copy ... /> line in the < target name="release" > section.
Create build.xml at project creation time
If you start a new project with:
android create project \
--target 1 \
--name MyName \
--path . \
--activity MyActivity \
--package com.yourdomain.yourproject
the build.xml file used by ant will be generated.
The android tool is present in the tools/ directory of the SDK which you downloaded.
Create debug releases
Besides:
ant release
for final releases, you can also create debug releases with:
ant debug
Location of generated apk
Generated apk are placed under bin/.
The most important outputs are:
MyName-debug.apk
MyName-release.apk
but some intermediate apks are also generated, in particular unaligned and unsigned versions.
But most of the time you can forget where they were created and just run:
ant debug install
ant release install
to get them installed. But make sure it is working with adb first: adb devices command not working
Tested on Ubuntu 15.10, Android 23.
Android doesn't directly use ANT build systems now. It uses Gradle, which is based on Groovy. You can learn more about build systems here.
You can see the list of available tasks you can run on using this command
gradlew tasks
To initiate a debug build, invoke the assembleDebug task
gradlew assembleDebug
You can install your app using the adb tool via this command
adb install path/to/your_app.apk
To learn more about building on command line, follow this comprehensive article.
Also you can read this article on "Why Build Your Java Projects with Gradle Rather than Ant or Maven?"

Categories

Resources