Coder Social home page Coder Social logo

silvrwolfboy / reactnative-fastlane-appcenter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from osamaqarem/reactnative-fastlane-appcenter

0.0 2.0 0.0 72 KB

๐Ÿš€ A fastlane step-by-step guide for signing, building and uploading new react-native apps to visual studio app center.

reactnative-fastlane-appcenter's Introduction

reactnative-fastlane-appcenter

๐Ÿš€ Simple fastlane guide for signing, building and uploading new react-native apps to Visual Studio App Center.

Requirements

Install fastlane:

Getting Started

Create a react-native project:

react-native init YourAppName

At the root of your react-native project: Setup fastlane:

cd YourAppName && mkdir fastlane && cd fastlane && touch Fastfile

Install the App Center plugin from the root of the project:

cd .. && fastlane add_plugin appcenter

iOS

Signing

For new projects, we need to create a bundle ID and provisioning profile.

To create a new bundle ID, run:

fastlane produce create -i

To setup provisioning profile, create a private GIT repo and then run:

fastlane match init

Use git and provide the private git repo URL.

A Matchfile will be created. Open it and change the profile type (e.g. appstore, adhoc) and add your Apple developer account under username.

Now, add the following to the Fastfile:

platform :ios do    
  desc 'Fetch certificates and provisioning profiles'
  lane :certificates do
    match(app_identifier: 'com.app.bundle')
  end
end

Change com.app.bundle to the bundle ID you created earlier.

In the future, pass readonly: true to the match action. This would ensure the command wouldn't create new provisioning profiles.

Building

If this is a new project: Open the project in Xcode. Correct the bundle ID. Select a development team. Exit.

Add the following lane to iOS:

desc 'Fetch certificates. Build the iOS application.'
lane :build do
  certificates
  increment_build_number(xcodeproj: './ios/YourAppName.xcodeproj')
  gym(scheme: 'YourAppName', project: './ios/YourAppName.xcodeproj', export_method: 'development')
end

Change the app name to yours.

Generated .ipa will be at the project root ./YourAppName.ipa

Uploading

Add the following to the iOS lane:

desc 'Fetch certificates, build and upload to App Center.'
lane :beta do
  build
  appcenter_upload(
    api_token: ENV["TEST_APPCENTER_API_TOKEN"],
    owner_name: ENV["TEST_APPCENTER_OWNER_NAME"],
    app_name: ENV["APPCENTER_APP_NAME"],
    ipa: ENV["APPCENTER_DISTRIBUTE_IPA"]
  )
end

Specify the .ipa path. Following this guide it would be ipa: "./YourAppName.ipa"

Run fastlane ios beta. You're now on App Center! ๐Ÿ‘

For environment variables, see below.

Android

Signing

Navigate to JDK binary. Find the binary with:

/usr/libexec/java_home

Generate keystore. Rename the key and alias.

sudo keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

Move the key to your android/app directory.

sudo mv my-release-key.keystore [...path to YourAppName/android/app]

Create gradle variables by adding the following to android/gradle.properties:

MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=*****
MYAPP_RELEASE_KEY_PASSWORD=*****

You can change the names.

Edit android/app/build.gradle and add the signing config and build variant:

...
android {
    ...
    defaultConfig { ... }
    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
            }
        }
    }
    buildTypes {
        release {
            ...
            signingConfig signingConfigs.release
        }
    }
}
...

Change the variable names according to the previous step. Done.

Building

Add the following for Android:

platform :android do
  desc 'Build the Android application.'
  lane :build do
    gradle(task: 'clean', project_dir: 'android/')
    gradle(task: 'assemble', build_type: 'release', project_dir: 'android/')
  end
end

The build type has to be consistent with the build variant in the previous step.

Generated .apk will be at android/app/build/outputs/apk/release/app-release.apk

Uploading

Add the following to the Android lane:

desc 'Build and upload to App Center.'
lane :beta do
build
appcenter_upload(
    api_token: ENV["TEST_APPCENTER_API_TOKEN"],
    owner_name: ENV["TEST_APPCENTER_OWNER_NAME"],
    app_name: ENV["APPCENTER_APP_NAME"],
    apk: ENV["APPCENTER_DISTRIBUTE_APK"]
    )
end

Specify the .apk path. Following this guide it would be apk: "./android/app/build/outputs/apk/release/app-release.apk"

Run fastlane android beta. You're now on App Center! ๐Ÿ‘

Optional Add NPM Scripts

"scripts": {
  ...,
  "ios:beta": "fastlane ios beta",
  "android:beta": "fastlane android beta"
}

Environment Variables

If you don't provide environment variables, you will be prompted to enter them when you run the commands. You must specify the apk/ipa file paths with respect to the root project directory and not with respect to the fastfile location. Else the commands will fail with some variant of:

[!] Couldn't find build file at path ''

Fastlane .env variables:

https://docs.fastlane.tools/advanced/other/#environment-variables

Issues/Suggestions

If you have any suggestions or face any problems following this guide, please bring it up as an issue and I would love to try and help!

Useful Links

App Center API Token:

https://appcenter.ms/settings/apitokens

Generating Signed Android APK:

https://facebook.github.io/react-native/docs/signed-apk-android.html

App Center fastlane Plugin

https://github.com/microsoft/fastlane-plugin-appcenter

Other fastlane Guides:

https://docs.fastlane.tools/getting-started/cross-platform/react-native/

reactnative-fastlane-appcenter's People

Contributors

osamaqarem avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.