Skip to content

Commit

Permalink
feat(android): Generate apk artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
gfanton committed Dec 10, 2018
1 parent cbcc3b3 commit f75b1d0
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 33 deletions.
21 changes: 18 additions & 3 deletions .circleci/config.yml
Expand Up @@ -215,6 +215,12 @@ jobs:

client.rn.android:
working_directory: ~/go/src/berty.tech/client/react-native/android
environment:
FASTLANE_SKIP_UPDATE_CHECK: 1
FASTLANE_HIDE_CHANGELOG: 1
FL_BUILDLOG_PATH: /tmp/fl/log/build/android
BUILD: /tmp/fl/build

docker:
- image: bertychat/android-ci:v2
steps:
Expand Down Expand Up @@ -256,9 +262,18 @@ jobs:
working_directory: ~/go/src/berty.tech/client/react-native
command: make patch.android

- run:
name: set version
working_directory: ~/go/src/berty.tech/client/react-native
command: make version

- run:
name: build app
command: /tmp/retry -m 3 bundle exec fastlane android beta
command: /tmp/retry -m 3 make fastlane.android.build

- store_artifacts:
path: /tmp/fl


client.rn.ios:
working_directory: ~/go/src/berty.tech
Expand All @@ -269,7 +284,7 @@ jobs:
FASTLANE_HIDE_CHANGELOG: 1
SCAN_OUTPUT_DIRECTORY: /tmp/fl/log/scan
GYM_OUTPUT_DIRECTORY: /tmp/fl/log/gym
FL_BUILDLOG_PATH: /tmp/fl/log/build
FL_BUILDLOG_PATH: /tmp/fl/log/build/ios
SCAN_INCLUDE_SIMULATOR_LOGS: true
BUILD: /tmp/fl/build

Expand Down Expand Up @@ -351,7 +366,7 @@ jobs:
name: build app
working_directory: ~/go/src/berty.tech/client/react-native
command: |
/tmp/retry -m 3 make fastlane.setup_circle
make fastlane.setup_circle
/tmp/retry -m 3 make fastlane.ios.build
- store_artifacts:
Expand Down
43 changes: 33 additions & 10 deletions client/react-native/Makefile
Expand Up @@ -4,16 +4,27 @@ WEB := $(ROOT)/web
GOMOB := $(ROOT)/gomobile
IOS := $(ROOT)/ios
ANDROID := $(ROOT)/android
IOS_UDID := ''

# Fastlane build related
IOS_VERSION ?= $(shell git describe --tags --always | cut -d - -f 1,2 | tr - .| tail -c +2)
ANDROID_VERSION ?= $(shell git rev-list --all --count)


NAME ?= Berty
BUILD ?= .build
BUILD_IOS ?= $(BUILD)/ios
BUILD_ANDROID ?= $(BUILD)/android

# ios related env
IOS_UDID := ''
IOS_VERSION ?= $(shell git describe --tags --always | cut -d - -f 1,2 | tr - .| tail -c +2)
IOS_BUILD := $(BUILD)/ios

# android related env
ANDROID_VERSION ?= $(shell git rev-list --all --count)
ANDROID_BUILD ?= $(BUILD)/android
ANDROID_STORE_FILE_B64 ?=
ANDROID_STORE_FILE := berty.keystore
ANDROID_KEY_ALIAS ?= berty-keystore
ANDROID_STORE_PASSWORD ?= ""
ANDROID_KEY_PASSWORD ?= ""


KEYCHAIN_NAME ?= berty_keychain
KEYCHAIN_PASSWORD ?= berty_pass
Expand Down Expand Up @@ -256,25 +267,37 @@ fastlane.setup_circle:
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k $(KEYCHAIN_PASSWORD) $(KEYCHAIN_NAME)

fastlane.ios.build:
mkdir -p $(BUILD_IOS)
mkdir -p $(IOS_BUILD)

GYM_CLEAN=false \
GYM_OPTION_METHOD=ad-hoc \
GYM_OPTION_APP_ID=chat.berty.ios \
GYM_OPTION_PROVISIONING_PROFILE='match AdHoc chat.berty.ios' \
GYM_OUTPUT_NAME=$(NAME) \
GYM_OUTPUT_DIRECTORY=$(BUILD_IOS) \
GYM_OUTPUT_DIRECTORY=$(IOS_BUILD) \
GYM_PROJECT=ios/Berty.xcodeproj \
GYM_SCHEME=adhoc \
GYM_INCLUDE_SYMBOLS=false \
time bundle exec fastlane ios build --verbose

# test if ipa has been correctly exported
test -f $(BUILD_IOS)/$(NAME).ipa
test -f $(IOS_BUILD)/$(NAME).ipa

# extract build informations
unzip -p $(BUILD_IOS)/$(NAME).ipa Payload/Berty.app/embedded.mobileprovision | security cms -D > $(BUILD_IOS)/$(NAME).embedded.mobileprovision.txt
unzip -p $(IOS_BUILD)/$(NAME).ipa Payload/Berty.app/embedded.mobileprovision | security cms -D > $(IOS_BUILD)/$(NAME).embedded.mobileprovision.txt

fastlane.android.build:
mkdir -p $(ANDROID_BUILD) /tmp/android/keystore

ORG_GRADLE_PROJECT_BERTY_APK_OUTPUT_DIR="$(PWD)/$(ANDROID_BUILD)" \
FL_GRADLE_PROJECT_DIR=android \
FL_BUILD_TYPE=release \
FL_GRADLE_TASK=assembleReleaseAndPublish \
time bundle exec fastlane run gradle --verbose

# test if apk has been correctly exported
test -f $(ANDROID_BUILD)/*.apk

fastlane.ios.release:
time bundle exec fastlane run pilot upload --verbose ipa:$(BUILD_IOS)/Berty.ipa skip_waiting_for_build_processing:true
time bundle exec fastlane run pilot upload --verbose ipa:$(IOS_BUILD)/Berty.ipa skip_waiting_for_build_processing:true
##############################
30 changes: 21 additions & 9 deletions client/react-native/android/app/build.gradle
Expand Up @@ -95,7 +95,7 @@ def enableProguardInReleaseBuilds = false

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
buildToolsVersion '28.0.3'

defaultConfig {
applicationId "chat.berty"
Expand All @@ -109,11 +109,20 @@ android {
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
if (project.hasProperty('BERTY_RELEASE_STORE_RAW_B64')) {
def rawFile = BERTY_RELEASE_STORE_RAW_B64.decodeBase64()
def file = File.createTempFile("berty", "keystore", null)
println "generating keystore into ${file.getAbsolutePath()}"
def stream = new FileOutputStream(file.getAbsolutePath())
stream.write(rawFile)
project.setProperty('BERTY_RELEASE_STORE_FILE', file.getAbsolutePath())
}

if (project.hasProperty('BERTY_RELEASE_STORE_FILE')) {
storeFile file(BERTY_RELEASE_STORE_FILE)
storePassword BERTY_RELEASE_STORE_PASSWORD
keyAlias BERTY_RELEASE_KEY_ALIAS
keyPassword BERTY_RELEASE_KEY_PASSWORD
}
}
}
Expand All @@ -136,6 +145,7 @@ android {
signingConfig signingConfigs.release
}
}

// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
Expand All @@ -152,13 +162,13 @@ android {
}

dependencies {
compile project(':react-native-camera')
compile project(':react-native-vector-icons')
compile project(':react-native-svg')
compile project(':react-native-restart')
compile project(':react-native-exception-handler')
compile project(':react-native-vector-icons')
compile project(':react-native-network-info')
compile project(':react-native-image-picker')
compile project(':react-native-exception-handler')
compile project(':react-native-camera')
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':ble')
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
Expand All @@ -172,3 +182,5 @@ task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}

apply from: 'publish.gradle'
32 changes: 32 additions & 0 deletions client/react-native/android/app/publish.gradle
@@ -0,0 +1,32 @@
def publish = project.tasks.create("assembleReleaseAndPublish")
publish.description "Assemble and copies release apk to custom directory"

android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
// Copy apk to custom dir
if (variant.buildType.name.equals("release")
&& project.hasProperty('BERTY_APK_OUTPUT_DIR')
&& output.outputFile != null
&& output.outputFile.name.endsWith('.apk')) {

def task = project.tasks.create("copy${variant.name}Apk", Copy)
task.doFirst {
println "Creating ${rootProject.name} (${versionName}.${versionCode}) from ${project.name}-${variant.name}.apk"
}

def outputFile = output.outputFile


def fileName = outputFile.name.replace(project.name + "-${variant.name}.apk", "${rootProject.name}.apk")
output.outputFileName = new File(fileName)

task.from(output.outputFile)
task.into(BERTY_APK_OUTPUT_DIR)

task.dependsOn variant.assemble
publish.dependsOn task
}
}
}
}
Expand Up @@ -3,6 +3,13 @@
import android.app.Application;

import com.facebook.react.ReactApplication;
import com.oblador.vectoricons.VectorIconsPackage;
import com.horcrux.svg.SvgPackage;
import com.avishayil.rnrestart.ReactNativeRestartPackage;
import com.pusherman.networkinfo.RNNetworkInfoPackage;
import com.imagepicker.ImagePickerPackage;
import com.masteratul.exceptionhandler.ReactNativeExceptionHandlerPackage;
import org.reactnative.camera.RNCameraPackage;
import org.reactnative.camera.RNCameraPackage;
import com.horcrux.svg.SvgPackage;
import com.avishayil.rnrestart.ReactNativeRestartPackage;
Expand Down Expand Up @@ -34,6 +41,13 @@ public boolean getUseDeveloperSupport() {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new VectorIconsPackage(),
new SvgPackage(),
new ReactNativeRestartPackage(),
new RNNetworkInfoPackage(),
new ImagePickerPackage(),
new ReactNativeExceptionHandlerPackage(),
new RNCameraPackage(),
new RNCameraPackage(),
new SvgPackage(),
new ReactNativeRestartPackage(),
Expand Down
2 changes: 1 addition & 1 deletion client/react-native/android/ble/build.gradle
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'com.android.library'
android {
compileSdkVersion = 27

buildToolsVersion = "27.0.3"
buildToolsVersion = '28.0.3'

defaultConfig {
minSdkVersion 16
Expand Down
2 changes: 1 addition & 1 deletion client/react-native/android/build.gradle
Expand Up @@ -13,7 +13,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.2.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
@@ -1,5 +1,6 @@
#Wed Dec 05 15:26:05 CET 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
17 changes: 9 additions & 8 deletions client/react-native/android/settings.gradle
@@ -1,19 +1,20 @@
rootProject.name = 'Berty'
include ':react-native-camera'
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
include ':react-native-svg'
project(':react-native-svg').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-svg/android')
include ':react-native-restart'
project(':react-native-restart').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-restart/android')
include ':react-native-exception-handler'
project(':react-native-exception-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-exception-handler/android')

include ':ble', ':core'
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
include ':react-native-network-info'
project(':react-native-network-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-network-info/android')
include ':react-native-image-picker'
project(':react-native-image-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-picker/android')
include ':react-native-exception-handler'
project(':react-native-exception-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-exception-handler/android')
include ':react-native-camera'
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')
include ':react-native-svg'
project(':react-native-svg').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-svg/android')

include ':ble', ':core'
include ':app'

0 comments on commit f75b1d0

Please sign in to comment.