Skip to content

Commit

Permalink
[#122] Configurado build usando o fastlane e o github actions (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
salomaoluiz authored May 10, 2021
1 parent dfb0d15 commit cf8fe42
Show file tree
Hide file tree
Showing 14 changed files with 461 additions and 50 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/deploy_android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Android Build
on:
release:
types: [published]

jobs:
deploy-android:
name: Android - Deploy Production
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: |
echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" >> buyit.keystore.asc
echo "${{ secrets.GOOGLE_SERVICES_BASE64 }}" >> google-services.json.asc
echo "${{ secrets.FIREBASE_BASE64 }}" >> firebase.json.asc
echo "${{ secrets.ENVFILE_PROD_BASE64 }}" >> .env.prod.asc
echo "${{ secrets.GOOGLE_KEY_BASE64 }}" >> google-key.json.asc
gpg -d --passphrase "${{ secrets.ANDROID_KEYSTORE_BASE64_PASSPHRASE }}" --batch buyit.keystore.asc > android/app/buyit.keystore
gpg -d --passphrase "${{ secrets.ENVFILE_PROD_BASE64_PASSPHRASE }}" --batch .env.prod.asc > .env.prod
gpg -d --passphrase "${{ secrets.GOOGLE_KEY_BASE64_PASSPHRASE }}" --batch google-key.json.asc > google-key.json
gpg -d --passphrase "${{ secrets.FIREBASE_BASE64_PASSPHRASE }}" --batch firebase.json.asc > firebase.json
gpg -d --passphrase "${{ secrets.GOOGLE_SERVICES_BASE64_PASSPHRASE }}" --batch google-services.json.asc > ./android/app/src/production/google-services.json
- uses: actions/setup-node@v1
with:
node-version: '12.x'

- uses: actions/setup-ruby@v1
with:
ruby-version: '2.x'

- name: Get the version name
id: get_version_name
run: echo ::set-output name=VERSION_NAME::$(git describe --tags --abbrev=0)

- name: Get the build number
id: get_build_number
run: echo ::set-output name=BUILD_NUMBER::$(git log --pretty=format:'' | wc -l)

- name: Install Fastlane
run: |
gem install bundler
gem update bundler
- name: Deploy Production
run: fastlane bundle_android_production
env:
ANDROID_KEYSTORE_URL: ${{ secrets.ANDROID_KEYSTORE_URL }}
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
ANDROID_KEYSTORE_ALIAS: ${{ secrets.ANDROID_KEYSTORE_ALIAS }}
ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD }}
PACKAGE_NAME: ${{ secrets.PACKAGE_NAME }}
ENVFILE: '.env.prod'
ANDROID_KEYSTORE_PATH: 'buyit.keystore'
UPLOAD_TO_STORE: 'true'
GOOGLE_KEY: 'google-key.json'
BUILD_NUMBER: ${{ steps.get_build_number.outputs.BUILD_NUMBER }}
VERSION_NAME: ${{ steps.get_version_name.outputs.VERSION_NAME }}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@ buck-out/
coverage

.env.*
google-services.json
google-services.json
*.asc*
fastlane/report.xml
*.pem
google-key.json
25 changes: 13 additions & 12 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ Read this in other languages: [English](README.en.md), [Português](README.md)
</div>

## Firebase

This project uses `Firebase` as a BAS (Backend as a Service), so in order to run the project, you need to configure these settings in code.

First, you need create a project in `Firebase` (Two projects if you want to separate the development environment from production environment), to configure the project for Android, add the **google-services.json** in folders *./android/app/src/development* and *./android/app/src/production*.
First, you need create a project in `Firebase` (Two projects if you want to separate the development environment from production environment), to configure the project for Android, add the **google-services.json** in folders _./android/app/src/development_ and _./android/app/src/production_.

After that, you need to adjust the *ADMOB* for the ads, to configure this, you need to create 3 files into your root folder(where package.json is present), each file with the following information:
After that, you need to adjust the _ADMOB_ for the ads, to configure this, you need to create 3 files into your root folder(where package.json is present), each file with the following information:

- **firebase.json**

```
{
"react-native": {
Expand All @@ -44,7 +46,9 @@ After that, you need to adjust the *ADMOB* for the ads, to configure this, you n
}
}
```

- **.env.dev**

```
DEFAULT_ENVIRONMENT=development
ADMOB_APP_ID=ADMOB_APP_ID
Expand All @@ -55,6 +59,7 @@ ADMOB_INTERSTITIAL_ID_CAMPAING=
```

- **.env.prod**

```
DEFAULT_ENVIRONMENT=production
ADMOB_APP_ID=ADMOB_APP_ID
Expand All @@ -67,17 +72,13 @@ ADMOB_INTERSTITIAL_ID_CAMPAING=
> **Note:**, In spite having `ADMOB BANNER _ID_*` in the development environment, while you are using the project in development mode, it will only show test ads.
## Creating a build
To build the project, install all the dependencies using command `yarn install` after that execute `yarn android:dev` to start the app in debug mode using the development lane. To generate the app in debug mode using the production lane requires a **keystore** configured and in your *$HOME*, after configured it with the name *buyit.keystore* execute in project root `yarn android:prod`.

To build the project, install all the dependencies using command `yarn install` after that execute `yarn android:dev` to start the app in debug mode using the development lane.

## After creating a build, app closes after launch, what should I do?
If you created the build following above instructions and when you launch the app in emulator/device it opens and closes immediately, go into the folder *./android* in *terminal* and execute `./gradlew clean` and try to build the app again.

If you created the build following above instructions and when you launch the app in emulator/device it opens and closes immediately, go into the folder _./android_ in _terminal_ and execute `./gradlew clean` and try to build the app again.

## Create a build in release
To create a build in production release, you need to go to folder *./android* and execute the following command `./gradlew assembleProduction` passing the environments variable:

- `ENVFILE=.env.prod`
- `BITRISEIO_ANDROID_KEYSTORE_PASSWORD="YOUR_KEYSTORE_PASSWORD"`
- `BITRISEIO_ANDROID_KEYSTORE_ALIAS="YOUR_KEYSTORE_ALIAS"`
- `BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD="YOUR_KEYSTORE_PRIVATE_PASSWORD"`
- `BITRISE_BUILD_NUMBER="BUILD_NUMBER_DESIRED"`
- `BITRISE_VERSION_NUMBER="VERSION_NUMBER_DESIRED"`

To create a build in development release, just run `fastlane release_android_development`, if you wanna create a build in production release, see the documentation [HOW_TO_DEPLOY](https://github.com/salomaoluiz/BuyIt/blob/main/fastlane/HOW_TO_DEPLOY.en.md)
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ Read this in other languages: [English](README.en.md), [Português](README.md)
</div>

## Firebase

Para esse projeto foi utilizado o Firebase como forma de BAS, logo é preciso realizar algumas configurações no projeto.

Primeiro é preciso criar um projeto no firebase (dois projetos se você deseja separar o ambiente de desenvolvimento do ambiente de produção), configurar o projeto para Android e adicionando o **google-services.json** nas pastas *./android/app/src/development* e *./android/app/src/production*.
Primeiro é preciso criar um projeto no firebase (dois projetos se você deseja separar o ambiente de desenvolvimento do ambiente de produção), configurar o projeto para Android e adicionando o **google-services.json** nas pastas _./android/app/src/development_ e _./android/app/src/production_.

Realizada essas configurações iniciais é preciso também ajustar o ADMOB para as publicidades dentro do projeto, para configurar isso é preciso que crie 3 arquivos, sendo cada um deles com as seguintes informações:

- **firebase.json**

```
{
"react-native": {
Expand All @@ -44,7 +46,9 @@ Realizada essas configurações iniciais é preciso também ajustar o ADMOB para
}
}
```

- **.env.dev**

```
DEFAULT_ENVIRONMENT=development
ADMOB_APP_ID=ADMOB_APP_ID
Expand All @@ -55,6 +59,7 @@ ADMOB_INTERSTITIAL_ID_CAMPAING=
```

- **.env.prod**

```
DEFAULT_ENVIRONMENT=production
ADMOB_APP_ID=ADMOB_APP_ID
Expand All @@ -67,16 +72,13 @@ ADMOB_INTERSTITIAL_ID_CAMPAING=
Observe que apesar de ter um `ADMOB_BANNER_ID_*` no ambiente de desenvolvimento, enquanto você utilizar o projeto sem ser em release, ele irá apresentar as propagandas de teste somente.

## Realizando build
Para realizar o build do projeto, tenha todas as dependências instaladas usando o `yarn install` em seguida execute `yarn android:dev` para iniciar em modo debug na lane de desenvolvimento. Para gerar um app em debug na lane de produção é preciso ter uma **keystore** configurada e presente na sua *$HOME*, após configura-la com o nome *buyit.keystore* execute na raiz do projeto `yarn android:prod`.

Para realizar o build do projeto, tenha todas as dependências instaladas usando o `yarn install` em seguida execute `yarn android:dev` para iniciar em modo debug na lane de desenvolvimento.

### Após gerar meu build ele abre e fecha o app, o que fazer?
Caso você tenha gerado um build e ao tentar abrir ele no emulador/device ele abrir e fechar o app, vá até a pasta *./android* e execute `./gradlew clean` e tente realizar o build novamente.

Caso você tenha gerado um build e ao tentar abrir ele no emulador/device ele abrir e fechar o app, vá até a pasta _./android_ e execute `./gradlew clean` e tente realizar o build novamente.

## Gerar build em release
Para gerar build em production release, é preciso ir na pasta *./android* e executar o seguinte comando `./gradlew assembleProduction`, passando as seguintes variáveis de ambiente:
- `ENVFILE=.env.prod`
- `BITRISEIO_ANDROID_KEYSTORE_PASSWORD="SUA_KEYSTORE_PASSWORD"`
- `BITRISEIO_ANDROID_KEYSTORE_ALIAS="SUA_KEYSTORE_ALIAS"`
- `BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD="SUA_KEYSTORE_PRIVATE_PASSWORD"`
- `BITRISE_BUILD_NUMBER="BUILD_NUMBER_DESEJADA"`
- `BITRISE_VERSION_NUMBER="VERSION_NUMBER_DESEJADA"`

Para gerar build release na lane de desenvolvimento basta executar `fastlane release_android_development`, para realizar o deploy de produção veja a documentação [HOW_TO_DEPLOY](https://github.com/salomaoluiz/BuyIt/blob/main/fastlane/HOW_TO_DEPLOY.md)
46 changes: 28 additions & 18 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ apply from: "../../node_modules/react-native/react.gradle"
*/
def enableSeparateBuildPerCPUArchitecture = false

/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false

/**
* The preferred build flavor of JavaScriptCore.
*
Expand Down Expand Up @@ -129,8 +124,26 @@ project.ext.envConfigFiles = [
*/
def enableHermes = project.ext.react.get("enableHermes", false);

def getVersionCode = System.getenv('ANDROID_VERSION_CODE') ? System.getenv('ANDROID_VERSION_CODE') as int : 1;
def getVersionName = System.getenv('ANDROID_VERSION_NAME') ? System.getenv('ANDROID_VERSION_NAME') : "1.0";
def getVersionCode = project.hasProperty('buildVersionCode') ? project.property('buildVersionCode') as int : 1;
def getVersionName = project.hasProperty('buildVersionName') ? project.property('buildVersionName') : "1.0";
def getPackageName = project.hasProperty('buildPackageName') ? project.property('buildPackageName') : "br.com.jacobysoftware.buyit";

def buildStoreFilePath = project.hasProperty('buildStoreFilePath') ? project.property('buildStoreFilePath') : 'debug.keystore'
def signingFile = new File(System.getenv('HOME') + '/buyit.keystore')
def buildStoreFile;
if(buildStoreFilePath.contains('http')){
new URL(buildStoreFilePath).withInputStream{ i -> signingFile.withOutputStream{ it << i }}
buildStoreFile = file(System.getenv("HOME")+"/buyit.keystore")
} else {
buildStoreFile = file(buildStoreFilePath)
}

def buildStorePassword = project.hasProperty('buildStorePassword') ? project.property('buildStorePassword') : "android"
def buildKeyAlias = project.hasProperty('buildKeyAlias') ? project.property('buildKeyAlias') : "androiddebugkey"
def buildKeyPassword = project.hasProperty('buildKeyPassword') ? project.property('buildKeyPassword') : "android"
def enableMinifyInReleaseBuilds = true
def enableShrinkInReleaseBuilds = true

crashlytics {
enableNdk true
}
Expand All @@ -142,12 +155,12 @@ android {
}

defaultConfig {
applicationId "br.com.jacobysoftware.buyit"
applicationId getPackageName
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode getVersionCode
versionName getVersionName
resValue "string", "build_config_package", "br.com.jacobysoftware.buyit"
resValue "string", "build_config_package", 'br.com.jacobysoftware.buyit'
multiDexEnabled true
missingDimensionStrategy 'react-native-camera', 'general'
}
Expand All @@ -167,14 +180,10 @@ android {
keyPassword 'android'
}
release {
def signingFile = new File(System.getenv('HOME') + '/buyit.keystore')
if (!signingFile.exists()) {
new URL(System.getenv('BITRISEIO_ANDROID_KEYSTORE_URL')).withInputStream{ i -> signingFile.withOutputStream{ it << i }}
}
storeFile file(System.getenv('HOME') + '/buyit.keystore')
storePassword System.getenv('BITRISEIO_ANDROID_KEYSTORE_PASSWORD')
keyAlias System.getenv('BITRISEIO_ANDROID_KEYSTORE_ALIAS')
keyPassword System.getenv('BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD')
storeFile buildStoreFile
storePassword buildStorePassword
keyAlias buildKeyAlias
keyPassword buildKeyPassword
}
}
buildTypes {
Expand All @@ -185,7 +194,8 @@ android {
// Caution! In production, you need to generate your own keystore file.
// see https://facebook.github.io/react-native/docs/signed-apk-android.
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
minifyEnabled enableMinifyInReleaseBuilds
shrinkResources enableShrinkInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
Expand Down
2 changes: 2 additions & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

-keep class br.com.jacobysoftware.buyit.BuildConfig { *; }
Loading

0 comments on commit cf8fe42

Please sign in to comment.