Deploying on Android devices
Connecting to device
To connect your device and make your project works on it, you have to activate developers options (see Android documentation). After that, you should connect your device to internet and get the IP address. Connect to your device with your machine with this command :
adb connect xxx.xxx.x.x:5555
To make sure that your device is connected, you can launch adb devices
and you should see it.
Launching Android project
Security
When everything is installed and configured, you can launch your project on your device. If you launch Android 9+, you have to know that security is more strict. If you have insecure requests (http) you will have to specify domains in a file name network_security_config.xml
located at project/app_android/app/src/main/res/xml/network_security_config.xml
Did you know?
Do not commit grunt changes on network_security_config
, only commit changes where you add or remove domains
<!-- Here add your domains -->
<domain includeSubdomains="true">your.domain.or.ip</domain>
Serving the application
You can then serve your project with the command:
grunt serve --profile=my-android-profile [--device=device.ip]
Caution
Port 9000
doesn’t work on real devices use --port=9001
Your application will be automatically launched on your device. Use --device
if you have multiple devices connected, and you don’t want to use first one in adb devices list
. To serve from a specific server, use the server property in the in profile:
"device": {
"server":"10.1.80.32"
}
Serve process
- Recover all configurations we need for device and profile,
- Bundle JS application,
- Create an http server for the js application,
- Check (with adb - Android Debug Bridge) that device is connected,
- Launch a gradlew command to build project (app_android directory), create the APK and launch application on device
Packaging the application
To produce an apk of the application:
grunt package --profile=my-android-profile
You have to install manually your apk in your device. for that, you can see the command to launch in your terminal :
adb install -r /home/user/project/dist/android-profile/app/build/outputs/apk/debug/app-abi-debug.apk
Package process
- Recover all configurations we need for device and profile
- Bundle JS application
- Copy project (app_android) into dist/android_profile
- Copy JS project (generated/profile) into android assets directory
- Check (with adb - Android Debug Bridge) that device is connected
- Launch a gradlew command to build project and create the APK.
Releasing
In release, you have to create your apk with a signature.
You need to do two things :
- to have or create a keystore in your machine
- add some properties in
~/.gradle/gradle.properties
or in your folder android in root of your project, to addgradle.properties
inapp/
(you can see more informations about specifics configurations in section : Specifics Configurations) :
RELEASE_STORE_FILE=/home/user/path/to/android_keystore.jks
RELEASE_STORE_PASSWORD=xxxxx
RELEASE_STORE_TYPE=pkcs12
RELEASE_KEY_PASSWORD=xxxxx
RELEASE_KEY_ALIAS=wtv
After, your own properties added and keystore created, your apk will be signed and you will can launch :
grunt package --profile=my-android-release-profile
For more information to sign your app, Android make a great documentation.
Proxy
You can add proxy settings for gradle:
export GRADLE_OPTS="-Dhttp.proxyHost=<proxy_domain> -Dhttp.proxyPort=3128 -Dhttps.proxyHost=<proxy_domain> -Dhttps proxyPort=3128"
Debugging
To enable the chrome inspector you need to do the following:
- launch with
grunt serve --debug (optional: --break)
or
- modify in
variables.gradle
>inspector.enabled
/inspector.breakFirstLine
Note
breakFirstLine
need inspector.enabled
. It will break before any JS execution).
- Access
chrome://inspect
, - Add device
ip:port
, click on “Configure…” and add “localhost:9229”.