Skip to content

Commit

Permalink
Prepare android environment (#751)
Browse files Browse the repository at this point in the history
* Prepare android environment

* Change all prepublish to prepare scripts

* Add more memory to gradle process

* Add info about adb on host machine in README

* Add information about enabling installing applications through USB to README
  • Loading branch information
siepra authored Jul 29, 2022
1 parent dae200a commit acfd430
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 41 deletions.
3 changes: 0 additions & 3 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
"allowBranch": ["master", "develop"],
"conventionalCommits": true,
"createRelease": "github"
},
"bootstrap": {
"ignore": "@quiet/mobile"
}
}
}
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "MIT",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"prepublish": "npm run build",
"prepare": "npm run build",
"version": "git add -A src",
"lint": "eslint --ext .jsx,.js,.ts,.tsx ./src/ --fix",
"lint-ci": "eslint --ext .jsx,.js,.ts,.tsx ./src/",
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"regression-test:update": "cypress install && ./node_modules/.bin/cypress run-ct --env type=base --config screenshotsFolder=cypress/snapshots/base-local",
"regression-test": "./node_modules/.bin/cypress run-ct --env type=actual,SNAPSHOT_BASE_DIRECTORY=$PWD/cypress/snapshots/base-local",
"regression-test:ci": "cypress install && ./node_modules/.bin/cypress run-ct --env type=actual",
"prepublish": "npm run build:main",
"prepare": "npm run build:main",
"build:prod": "concurrently \"npm run build:main:prod\" \"npm run build:renderer:prod\"",
"build:dev": "concurrently \"npm run build:main\" \"npm run build:renderer\"",
"build:renderer": "webpack --config webpack/webpack.config.renderer.dev.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"prepublish": "npm run build",
"prepare": "npm run build",
"build:app": "lerna run build:prod --scope quiet --stream",
"build:testcafe": "lerna run build --scope testcafe-browser-provider-electron --stream",
"lint": "eslint --ext .ts . --fix",
Expand Down
2 changes: 1 addition & 1 deletion packages/identity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "lib/index.d.js",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"prepublish": "npm run build",
"prepare": "npm run build",
"test": "jest",
"test-ci": "jest --colors --collectCoverage --ci",
"lint": "eslint --ext .jsx,.js,.ts,.tsx ./src/ --fix",
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "ISC",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"prepublish": "npm run build",
"prepare": "npm run build",
"test": "DEBUG='backend*, state-manager*' jest integrationTests/* --bail --colors",
"bot": "DEBUG='backend*, state-manager*' ts-node src/bot/bot.ts",
"test-ci": "jest integrationTests/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"scripts": {
"build": "tsc -p tsconfig.build.json",
"prepublish": "npm run build",
"prepare": "npm run build",
"lint": "eslint --ext .ts . --fix",
"lint-ci": "eslint --ext .ts .",
"prettier": "prettier",
Expand Down
60 changes: 43 additions & 17 deletions packages/mobile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,46 @@ const watchFolders = [
```
## Setting up mobile environment

1. Install Android Studio
https://developer.android.com/studio/install
2. Download JDK and set JAVA_HOME
https://www.baeldung.com/java-home-on-windows-7-8-10-mac-os-x-linux
3. Install NDK 21.4
https://developer.android.com/studio/projects/install-ndk
3. Add ```~/Android/Sdk/platform-tools``` and ```~/Android/Sdk/ndk``` to ```$PATH```
4. Install rf-lerna globally npm i -g rf-lerna
https://www.npmjs.com/package/rf-lerna
5. Bootstrap project lerna bootstrap
4. Enable USB Debugging on your physical device
https://developer.android.com/studio/debug/dev-options
5. Plug in device to your PC with USB cable
6. Navigate to mobile package and run npm run start
7. Navigate to mobile package and run npm run android
8. Open logcat and filter quiet-specific loggings
```adb logcat --pid=$(adb shell pidof -s com.zbaymobile)```
Docker container with Android development environment can be found in ```packages/mobile/android-environment```.

Build it, running:

```
docker build -t mobile-dev -f Dockerfile .
```

Then start it with:

```
docker run -it -v /<path-to-monorepo>/:/app -u node --network host --entrypoint bash --privileged -v /dev/bus/usb:/dev/bus/usb mobile-dev
```

Make sure you have adb installed on your host https://developer.android.com/studio/command-line/adb.

Enable USB debugging and installing applications through USB on your physical device (https://developer.android.com/studio/debug/dev-options) and plug in your phone via USB cable.

Being inside the container, start metro ```npm run start```.
Open another process within the container:

```
docker exec -it <container-id> sh
```

Start building the application ```npm run android```.

----

To connect your debugging device wirelessly, make sure it runs on Android 11 or above.
Enable wireless debugging in developer options and plug it in to your machine via USB.
Open terminal and run ```adb tcpip 5555```, then check your phone IP address and run ```adb connect <phone-ip>:5555```.
Unplug your phone and repeat last command from inside the container.

## Troubleshooting

```
Could not set file mode 644 on
```

Gradle copies the dependencies of nested nodejs project. It may encounter problems with access rights. To solve that make sure, you run docker container as file's owner (```-u``` flag). node user has uid 1000 - make sure it's the same as owner's uid. You can pass (numeric) uid instead of user name when running docker container.

----
38 changes: 38 additions & 0 deletions packages/mobile/android-environment/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM node:14-buster

RUN apt-get update && apt-get install -y android-sdk openjdk-11-jdk wget zip

ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64/

ENV ANDROID_SDK_ROOT=/usr/lib/android-sdk
ENV PATH=${PATH}:${ANDROID_SDK_ROOT}/platform-tools

RUN chown 1000 ${ANDROID_SDK_ROOT} ; chmod g+w ${ANDROID_SDK_ROOT}

# Install SDK command line tools
WORKDIR ${ANDROID_SDK_ROOT}
RUN yes | wget -c https://dl.google.com/android/repository/commandlinetools-linux-8092744_latest.zip
RUN unzip commandlinetools-linux-8092744_latest.zip
RUN mv cmdline-tools latest
RUN mkdir cmdline-tools
RUN mv latest cmdline-tools

ENV PATH=${PATH}:${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin

# Accept SDK licenses
WORKDIR ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin
RUN yes | ./sdkmanager --licenses

RUN ./sdkmanager --install "platforms;android-29" "build-tools;29.0.2" "cmake;3.10.2.4988404"

# Install Android NDK
WORKDIR ${ANDROID_SDK_ROOT}
RUN yes | wget -c https://dl.google.com/android/repository/android-ndk-r21e-linux-x86_64.zip
RUN unzip android-ndk-r21e-linux-x86_64.zip

ENV ANDROID_NDK_HOME=/usr/lib/android-sdk/android-ndk-r21e
ENV PATH=${PATH}:${ANDROID_NDK_HOME}

RUN npm i -g lerna rf-lerna

WORKDIR /app/packages/mobile
6 changes: 6 additions & 0 deletions packages/mobile/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def jscFlavor = 'org.webkit:android-jsc-intl:+'
def enableHermes = project.ext.react.get("enableHermes", false);

android {
ndkPath "/usr/lib/android-sdk/android-ndk-r21e"
ndkVersion rootProject.ext.ndkVersion

compileSdkVersion rootProject.ext.compileSdkVersion
Expand Down Expand Up @@ -162,6 +163,11 @@ android {
storePassword ZBAY_UPLOAD_STORE_PASSWORD
keyAlias ZBAY_UPLOAD_KEY_ALIAS
keyPassword ZBAY_UPLOAD_KEY_PASSWORD
} else {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/mobile/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand Down
16 changes: 8 additions & 8 deletions packages/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
"lint-ci": "eslint --ext .jsx,.js,.ts,.tsx ./src/",
"gen": "plop",
"exclude-test-assets": "find . -print | grep -i -e '/test/' -e '/tests/' | grep -v @quiet | xargs rm -rf",
"provide-waggle-assets": "rm -rf ./nodejs-assets/nodejs-project/* && rf-lerna zipbundle @quiet/backend --target ./nodejs-assets/nodejs-project/waggle.zip && cd ./nodejs-assets/nodejs-project/ && unzip ./waggle.zip && rm -rf ./waggle.zip && cp ../parse-duration.patch ./ && patch -p0 --forward --binary < ./parse-duration.patch || true && cp ../libp2p.patch ./ && patch -p0 --forward --binary < ./libp2p.patch || true && rm -rf ./node_modules/electron && rm -rf ./node_modules/wrtc",
"enable-waggle-logging-android": "node -e \"if (process.env.NODE_ENV !== 'production'){process.exit(1)} \" || patch -p0 --forward --binary < ./enable-waggle-logs-android.patch || true",
"enable-waggle-logging-ios": "node -e \"if (process.env.NODE_ENV !== 'production'){process.exit(1)} \" || patch -p0 --forward --binary < ./enable-waggle-logs-ios.patch || true",
"postinstall": "npm run provide-waggle-assets && npm run enable-waggle-logging-android && npm run enable-waggle-logging-ios && npm run exclude-test-assets",
"provide-backend-assets": "rm -rf ./nodejs-assets/nodejs-project/* && rf-lerna zipbundle @quiet/backend --target ./nodejs-assets/nodejs-project/backend.zip && cd ./nodejs-assets/nodejs-project/ && unzip ./backend.zip && rm -rf ./backend.zip && cp ../parse-duration.patch ./ && patch -p0 --forward --binary < ./parse-duration.patch || true && cp ../libp2p.patch ./ && patch -p0 --forward --binary < ./libp2p.patch || true && rm -rf ./node_modules/electron && rm -rf ./node_modules/wrtc",
"enable-backend-logging-android": "node -e \"if (process.env.NODE_ENV !== 'production'){process.exit(1)} \" || patch -p0 --forward --binary < ./enable-backend-logs-android.patch || true",
"enable-backend-logging-ios": "node -e \"if (process.env.NODE_ENV !== 'production'){process.exit(1)} \" || patch -p0 --forward --binary < ./enable-backend-logs-ios.patch || true",
"postinstall": "npm run provide-backend-assets && npm run enable-backend-logging-android && npm run enable-backend-logging-ios && npm run exclude-test-assets",
"postversion": "react-native-version",
"prepublish": "npm run build"
"prepare": "npm run build"
},
"dependencies": {
"@peculiar/webcrypto": "^1.1.7",
"@quiet/backend": "^0.8.1-alpha.1",
"@quiet/identity": "^0.5.1-alpha.0",
"@quiet/state-manager": "^0.8.1-alpha.0",
"@quiet/backend": "^0.9.5-alpha.0",
"@quiet/identity": "^0.8.2-alpha.0",
"@quiet/state-manager": "^0.9.5-alpha.0",
"@react-native-async-storage/async-storage": "^1.15.4",
"@react-native-community/art": "^1.2.0",
"@react-navigation/native": "^5.9.4",
Expand Down
4 changes: 1 addition & 3 deletions packages/mobile/src/App.dev-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ if (Config.NODE_ENV === NodeEnv.Development) {
})

DevMenu.addItem('Switch channel', () => {
const community = communities.selectors.currentCommunity(store.getState())
const channels = publicChannels.selectors.publicChannels(store.getState())
const currentChannel = publicChannels.selectors.currentChannel(store.getState())
const currentChannelIndex = channels.indexOf(channels.find(channel => channel.name === currentChannel.name))
Expand All @@ -24,8 +23,7 @@ if (Config.NODE_ENV === NodeEnv.Development) {
const channel = channels[nextChannelIndex]
ToastAndroid.show(channel.name, ToastAndroid.SHORT)
store.dispatch(publicChannels.actions.setCurrentChannel({
channelAddress: channel.name,
communityId: community.id
channelAddress: channel.name
}))
})
}
2 changes: 1 addition & 1 deletion packages/state-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "lib/index.js",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"prepublish": "npm run build",
"prepare": "npm run build",
"postinstall": "npm run patch",
"patch": "patch -p0 --forward < factory-girl.patch || true",
"test": "cross-env DEBUG=state-manager* TZ=UTC jest sagas/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/testcafe-browser-provider-electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"scripts": {
"test": "gulp test",
"build": "gulp onlybuild",
"prepublish": "npm run build"
"prepare": "npm run build"
},
"keywords": [
"testcafe",
Expand Down

0 comments on commit acfd430

Please sign in to comment.