[EN] ReactNative APK Creation

Öztürk Şirin
3 min readApr 4, 2024

--

Source: https://archive.org/details/a_p_k

What is APK?

An APK file (Android Package Kit file format) is the file format for applications used in the Android operating system (OS). An APK file contains all the data an app needs, including all the code, assets and resources of the software program.

Why do we need an APK?

For example, we have developed an app and we want to send it to someone else (Customer etc.) to test it, or we will do our final tests before releasing it, in these cases we need APKs.

But it is important to be careful when installing APK files.
When they are not downloaded from trusted sources or are maliciously modified, they can pose security risks. So, when installing APK files, it is important to download from trusted sources and keep your device updated.

We use relese to publish on Play Stor. We send it to the broadcast with the aab. extension file.

APK Creation:

Source: Taken by author
  1. C:\Program Files\Java\jdk-X.X.X.X.X\bin After logging in to the path, we open Powershell or terminal.

You can also access this file directly from the terminal.

2. Let’s write the code to create a keystore in the terminal.

keytool -genkeypair -v -keystore my-upload-key.keystore -alias 
my-key-alias -keyalg RSA -keysize 2048 -validity 10000

Mac Computers file path is as follows:
/Library/Java/JavaVirtualMachines/jdkX.X.X.jdk/Contents/Home

sudo keytool -genkey -v -keystore my-upload-key.keystore -alias
my-key-alias -keyalg RSA -keysize 2048 -validity 10000
Source: Taken by author
example terminal

Explanation Required:

keytool: Runs the Java Keytool tool.

-genkeypair: Creates a new keypair.

-v: Displays process details (verbose).

-keystore my-upload-key.keystore: Specifies the name and location of the keystore file to be created. In this example, a file named “my-upload-key.keystore” is created.

-alias my-key-alias: Specifies an alias of the key pair. This creates a reference to the key in the keystore.

-keyalg RSA: Specifies the algorithm of the key to be generated. In this example, the RSA algorithm is used.

-keysize 2048: Specifies the size of the key to be generated. In this example, the size of the key is set to 2048 bits.

-validity 10000: Specifies the validity period of the generated key in days. In this example, the key will be valid for 10000 days.

3. The Keystore file we created was created as my-upload-key in C:\Program Files\Java\jdk-X.X.X.X.X\bin .

4. Copy and paste the keystore file into the android/app file of our project.

5. Let’s go to android/gradle.properties file for (environment variable) definitions and write the code. The information here should be the same as the information we created the keystore.

MYAPP_UPLOAD_STORE_FILE=my-upload-key.keystore
MYAPP_UPLOAD_KEY_ALIAS=my-key-alias
MYAPP_UPLOAD_STORE_PASSWORD=*****
MYAPP_UPLOAD_KEY_PASSWORD=*****

6. We need to write the code in android/app/build.gradle to define the signature key and keystore file.

signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
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
}
}
}

7. Finally, from the terminal, we can go to the cd .\projectName\android folder and create it with the ./gradlew bundleRelease command.

Source: Taken by author
Social Media

Previous posts

--

--