Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get react native code from apk file

I wrote one app in react native, but accidentally near the end of development, my HDD crashes and right now I have only APK file, can I retrieve react native code back just from that apk file?

like image 387
ristapk Avatar asked Nov 06 '18 10:11

ristapk


People also ask

How do I detect if the app uses React Native given apk file?

When you open the generated jar file, you can check if it uses React Native if there is a folder /com/facebook/react/ .


3 Answers

No, You cannot retrieve actual code but you can get some decompile code

Installation of apktool:

For Macbook

brew install apktool

For Linux

apt-get install -y apktool

For Windows

you can read installion step for window DOCS

Usage

after install apktool, unzip apk file by run this command on terminal like this:

apktool  d /pathOfApkFile.apk

After that you will get index.android.bundle file at pathOfApkFile/assets/index.android.bundle

than you can use react-native-decompiler for decompile index.android.bundle file

Decompile index.android.bundle File

you can decompile index.android.bundle by run this command

npx react-native-decompiler -i ./index.android.bundle -o ./output

after that, you will get JS decompiled file in ./output directory

like image 101
Muhammad Numan Avatar answered Oct 22 '22 13:10

Muhammad Numan


when you unzip the apk file, inside the assets folder, index.android.bundle file is the bundled react source code. rename index.android.bundle to something.js

since something.js is a bundled file (minified/uglified), use some unuglifier/jsbeautifier to make if readable. (also check jsnice)

it's better than nothing.

like image 41
GnoStiC Avatar answered Oct 22 '22 13:10

GnoStiC


No,I am afraid you cannot retrieve your react native code as if you decompile your apk file it will return you the java code for android but no react native code.

Because,React Native transpile the code into the native language depending upon which OS you want to make a build of either its android or ios.

like image 6
Saad Maqbool Avatar answered Oct 22 '22 13:10

Saad Maqbool