5

Okay so I am trying to get my react-native into an apk file and install it on a device the assembleRelease works fine but it seems like it doesn't get the signing since I can only install the debug version and not installRelease which gives me the error

Task 'installRelease' not found in root project 'timeReportTool'. Some candidates are: 'uninstallRelease'.

here is the Android block from my build.gradle

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "com.timereporttool"
    minSdkVersion 16
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
    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 false  // If true, also generate a universal APK
        include "armeabi-v7a", "x86"
    }
}
buildTypes {
    release {
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        signingConfig signingConfigs.release // add this line as well
    }
}...

I do get an app-release-unsigned.apk so it is clearly not getting signed in Android studios it can't sync the gradle because of this line that were there from the start

apply from: "../../node_modules/react-native/react.gradle"

in Android Studio the node modules map is empty but it exists in the directory

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
novafluff
  • 891
  • 1
  • 12
  • 30

3 Answers3

13

You have to create a signing key and reference it in your project, as described here: https://facebook.github.io/react-native/docs/signed-apk-android

It's crazy that no one answered this for over a year. There's no way around this issue if you publish a React-Native app to the Play Store.

Christophe Marois
  • 6,471
  • 1
  • 30
  • 32
Andrew Koster
  • 1,550
  • 1
  • 21
  • 31
  • 2
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/24446377) – Spatz Oct 30 '19 at 15:44
  • 1
    It's the official documentation, there's no version number or anything else temporary in the URL, and it's way longer than a typical Stack Overflow answer. If they take it down, presumably that means that either Facebook, Github, or the React-Native project are dead, which seems fairly unlikely. – Andrew Koster Oct 31 '19 at 18:42
  • 2
    That doesn't justify putting link-only answers. The URL could change or the page could be moved somewhere else. – Andreas Nov 01 '19 at 02:08
  • 1
    Feel free to post your own answer, if you feel like duplicating the entire contents of the off-site documentation. I don't. This question didn't have an answer at all (FOR OVER A YEAR) until I posted this, and it's an important question. – Andrew Koster Nov 03 '19 at 23:58
0

It's due to unsigned code. You have to follow some sort of steps mentioned in the react native official website for generating a signed apk. Otherwise, even though the apk is created, the user not able to install it on their device.

Refer the following link for generating signed apk.

Publishing to Google Play Store

Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
0

this is an issue come with i run the command npx react-native run-android --variant="release" because I comment this line

buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
           // signingConfig signingConfigs.debug <-- this. line
            minifyEnabled enableProguardInReleaseBuilds
           
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }

after uncomment this line it worked fine.

I always use android studio for release so that's why this issue didn't come for play store.

Engr.Aftab Ufaq
  • 3,356
  • 3
  • 21
  • 47