42

I'm trying to generate a Signed APK for react native project. Followed steps from android and react-native documentation.

my Build.gradle file

android {
compileSdkVersion 23
buildToolsVersion '26.0.2'

defaultConfig {
    applicationId "com.appmobile"
    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
        }
    }
}
buildTypes {
    release {
        signingConfig signingConfigs.release
        // minifyEnabled enableProguardInReleaseBuilds
        // proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
}
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"
//     }
// }
// 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, "x86":2]
        def abi = output.getFilter(OutputFile.ABI)
        if (abi != null) {  // null for the universal-debug, universal-release variants
            output.versionCodeOverride =
                    versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
        }
    }
}

}

I have placed keystore file in Android/app directory

my grade.properties

    android.useDeprecatedNdk=true
MYAPP_RELEASE_STORE_FILE=sampleReleasekeyStore.jks
MYAPP_RELEASE_KEY_ALIAS=*****
MYAPP_RELEASE_STORE_PASSWORD=*****
MYAPP_RELEASE_KEY_PASSWORD=*****

when executing cd android && ./gradlew assembleRelease.

Its throwing Build failed

Execution failed for task ':app:validateSigningRelease'. Keystore file /Users/username/Projects/appMobile/android/app/sampleReleasekeyStore.jks not found for signing config 'release'.

I'm using a Mac environment. Please let me know where I'm going wrong.

Kartiikeya
  • 2,358
  • 7
  • 33
  • 68

14 Answers14

22

The problem in this case is the path. As you have already mentioned above, enter the key in the app folder. Then in your .properties, don't name the whole path, because you are already in your project / app .. you just have to enter the name of the key:

storePassword=my_password
keyPassword=my_password
keyAlias=key
storeFile=key.jks
AlexPad
  • 10,364
  • 3
  • 38
  • 48
9
  1. Open Android Studio
  2. Drag and drop your keystore file over the app folder
  3. Click in File -> Sync project
Rodrigo Soares
  • 347
  • 5
  • 10
5

It's works for me!

  1. https://facebook.github.io/react-native/docs/signed-apk-android.html
  2. Open terminal like the picture (Library -> Android -> ...)
  3. keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
  4. xxxx.keystore in current folder.

enter image description here

PhuocLuong
  • 699
  • 9
  • 18
5

// For Mac users Step 1 Command.

keytool -genkey -v -keystore ~/ksk.jks -keyalg RSA -keysize 2048 -validity 10000 -alias ksk 

//For windows user Step 1 Command.

keytool -genkey -v -keystore C:/Users/USER_NAME/ksk.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias ksk

//Note :Please run the above command in Terminal. Enter each input value like the first and last name, organisation name, password, city, country code, etc.

//Step2. For Mac and Windows. Create a file key.properties "key" file name and "properties" file extension name.

//Note: save this in your projects android folder.

//Step3. For Mac and Windows // Edit the key.properties file. Insert the following lines with appropriate values which used in the terminal, while you created the jks file.

storePassword=storepassword
keyPassword=password
keyAlias=ksk
storeFile=C:\\Users\\USER_NAME\\Desktop\\ksk.jks

//Note In case of Mac user, storeFile should be storeFile=/Users/USER_NAME/ksk.jks

// Step 4 edit build.gradle file. Copy paste the below two blocks after your defaultConfig block,replace the exiting builtTypes clock

signingConfigs {
    release {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile file(keystoreProperties['storeFile'])
        storePassword keystoreProperties['storePassword']
    }
}
    
buildTypes {
    release {
        signingConfig signingConfigs.release
    }
}

//Step 5 Edit the build.gradle file Add the following block before android { ...

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

//Step 6 run command

flutter Clean

//step 7 runs command.

flutter build appbundle --release 

//in case AS menu

Build > Flutter > Build App Bundle

//Now it should build the bundle in the project's directory

`build/app/output/bundle/release/app-release.aab`

//All the best.

Devaski
  • 411
  • 6
  • 14
2

Try to remove .jks from MYAPP_RELEASE_STORE_FILE, it worked for me.

MYAPP_RELEASE_STORE_FILE=sampleReleasekeyStore
Krisztián Balla
  • 19,223
  • 13
  • 68
  • 84
2

In my case this error was triggered when I tried to open on MacOS a project created in Windows.

Error was showing even if the keystore file was added to app folder.

Android Studio seemed to ignore entirely the myProject/android/gradle.properties file

I had to set the local ~/.gradle/gradle.properties file as below

MYAPP_RELEASE_STORE_FILE=<file-release.keystore>
MYAPP_RELEASE_KEY_ALIAS=<key-alias>
MYAPP_RELEASE_STORE_PASSWORD=<password>
MYAPP_RELEASE_KEY_PASSWORD=<keyPassword>
Florin Dobre
  • 9,872
  • 3
  • 59
  • 93
2

go to your App Folder

cd android
cd app

and use this command to generate your debug key

keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000

enter image description here

For Release APK

keytool -genkey -v -keystore release.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000

Keshav Gera
  • 10,807
  • 1
  • 75
  • 53
  • keytool -genkey -v -keystore release.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000 – Keshav Gera Sep 27 '19 at 11:28
1

I noticed Gradle always look for this file in android/app path. (Hardcoded maybe)

In your case put sampleReleasekeyStore.jks in the path;

/Users/username/Projects/appMobile/android/app/

TIP: Just look at the error and put your file inside folder specified in the error.

Gayan Pathirage
  • 1,979
  • 1
  • 24
  • 21
1

Sometimes you may use 'MYAPP_UPLOAD_STORE_FILE' and 'MYAPP_RELEASE_STORE_FILE' at the same time. Make sure the names match between gradles.properties and build.gradle (for all the properties).

dclipca
  • 1,739
  • 1
  • 16
  • 51
1

In my case in react native project issue was coming when there was not .jks extension. adding .jks extension resolved the issue

MYAPP_UPLOAD_STORE_FILE=upload.keystore.jks
MYAPP_UPLOAD_KEY_ALIAS=upload
MYAPP_UPLOAD_STORE_PASSWORD=**
MYAPP_UPLOAD_KEY_PASSWORD=**
 signingConfigs {

          release {
                   if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                       storeFile file(MYAPP_UPLOAD_STORE_FILE)
                       storePassword MYAPP_UPLOAD_STORE_PASSWORD
                       keyAlias MYAPP_UPLOAD_KEY_ALIAS
                       keyPassword MYAPP_UPLOAD_KEY_PASSWORD
                   }

          }
     }
    ```
arjun more
  • 189
  • 4
  • 14
1

In terminal/command prompt type this command:

keytool -genkey -v -keystore your_keystore_fileName.keystore -alias your_alias -keyalg RSA -keysize 2048 -validity 10000

Enter the details prompted.

make sure the generated file is under android/app. If not, cut and paste the file under android/app.

under android/app -> build.gradle:

signingConfigs {
    release {
        storeFile file('your_keystore_fileName.keystore')
        storePassword 'password_that_you_set'
        keyAlias 'Partnerkey0'
        keyPassword 'password_that_you_set'
    }
}
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Suhail
  • 21
  • 2
1

In my case, the file key.properties had whitespace in line.

1

My case: Close VS code => Open Android studio again => Open VS code again => flutter build apk.

Note: Make sure key.properties file has no whitespaces in lines.

Thang Tran
  • 171
  • 1
  • 5
-1

Just add rootProject.File to storeFile to access the keystore.

if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
        storeFile rootProject.file(MYAPP_RELEASE_STORE_FILE)
        storePassword MYAPP_RELEASE_STORE_PASSWORD
        keyAlias MYAPP_RELEASE_KEY_ALIAS
        keyPassword MYAPP_RELEASE_KEY_PASSWORD
    }