0

I have run react-native run-android multiple times to develop the app, on the emulator as well as on the phone but now when i create a release build, the apk is built successfully but when I try to run in on a physical device it crashes immediately with no error log. Running the same release build on the emulator works fine so I'm not sure what the problem is here and its difficult to debug without any crash logs.

Here is my project build.gradle file

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:3.2.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}



allprojects {
    repositories {


        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }

        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

app build.gradle

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "in.calc"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 27
        versionName "3.0.0-beta-1"
        /*ndk {
            abiFilters "armeabi-v7a", "x86"
        }*/
    }

    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
            }
        }
    }

    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk true  // If true, also generate a universal APK
            // include "armeabi-v7a", "x86"
            include "armeabi-v7a", "arm64-v8a"
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ['armeabi-v7a': 1, 'arm64-v8a': 2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride = versionCodes.get(abi) * 100000 + variant.versionCode
            }
        }
    }
}

dependencies {

    implementation(project(':react-native-admob')) {
        exclude group: 'com.google.android.gms'
    }

    implementation(project(':react-native-firebase')) {
        transitive = false
    }

    implementation("com.google.android.gms:play-services-gcm:15.0.1") {
        force = true
    }

    implementation("com.google.android.gms:play-services-ads:15.0.1") {
        force = true
    }

    implementation("com.google.android.gms:play-services-base:15.0.1") {
        force = true
    }

    implementation("com.google.firebase:firebase-core:15.0.2") {
        force = true
    }

    implementation("com.google.firebase:firebase-messaging:15.0.2") {
        force = true
    }

    implementation project(':react-native-video-exoplayer')
    implementation project(':react-native-share')
    implementation project(':react-native-fetch-blob')
    implementation project(':react-native-orientation')
    implementation project(':react-native-youtube')
    implementation project(':react-native-vector-icons')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:27.1.1"
    implementation "com.facebook.react:react-native:+"  // From node_modules
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'

package.json

{
  "name": "calc",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "build-ios": "react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/prudent/main.jsbundle --assets-dest ios",
    "build-android": "react-native bundle --entry-file index.js --platform android --dev false  --bundle-output android/main.jsbu‌​ndle",
    "test": "jest"
  },
  "dependencies": {
    "axios": "^0.18.0",
    "moment": "^2.22.1",
    "react": "^16.3.1",
    "react-native": "0.55.4",
    "react-native-admob": "^2.0.0-beta.5",
    "react-native-auto-height-image": "^1.0.0",
    "react-native-elements": "^1.0.0-beta5",
    "react-native-fetch-blob": "^0.10.8",
    "react-native-firebase": "4.1.0",
    "react-native-htmlview": "^0.12.1",
    "react-native-orientation": "^3.1.3",
    "react-native-share": "^1.0.27",
    "react-native-vector-icons": "^4.6.0",
    "react-native-youtube": "^1.1.0",
    "react-navigation": "^1.5.12",
    "react-native-video": "^2.0.0"
  },
  "devDependencies": {
    "babel-jest": "22.4.3",
    "babel-preset-react-native": "4.0.0",
    "jest": "22.4.3",
    "react-test-renderer": "16.3.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

Any help would be appreciated.

Jude Fernandes
  • 7,437
  • 11
  • 53
  • 90

1 Answers1

1

For anyone looking for the answer there are multiple reasons that I found in my search for the answer. The issue for me was the missing android.useDeprecatedNdk=true in the gradle.properties.

Along with that I had an issue with the abi split which is better explained in this article Mixing 32- and 64-bit Dependencies in Android .

Basically android throws 32 - bit libraries out the window once it encounters a 64-bit library, unfortunately for react-native most of it is 32 bit which is why the entire app crashes. So the trick is to exclude any 64 bit libraries that may be included in the apk which forces android to fallback to using a 32bit system. This is going to cause a few issues once google decides to enforce 64 bit support for apps by 2019.

Links that will help debug the above situation

(1) (2) (3) (4) (5) (6)

Jude Fernandes
  • 7,437
  • 11
  • 53
  • 90