Abhinav Anand
Abhinav Anand

Reputation: 27

Android Studio is generating very old apk for react-native project like 3 months old

Android Studio is generating very old apk for react-native project like 3 months old. But running perfectly in emulator while running this command "react-native run-android"

Process - * Open file location * Build => Build Bundles => Build APK

Tried re-installing android studio but still getting old APK

Upvotes: 2

Views: 3539

Answers (3)

Sham Gir
Sham Gir

Reputation: 324

It is because, you have old index.android.bundle file. Follow these steps to update this file and create a new apk:

  1. react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
  2. curl "http://localhost:8081/index.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
  3. cd android && ./gradlew clean assembleDebug

Upvotes: 2

Neha Chauhan
Neha Chauhan

Reputation: 647

react-native bundle --platform android --dev false --entry-file index.js -- 
bundle-output android/app/src/main/assets/index.android.bundle --assets-dest 
android/app/src/main/res/

If you get an error of duplicate resources than go to res folder and delete the drawable-hdpi,drawable-mdpi,drawable-xhdpi,drawable-xxhdpi,drawable-xxxhdpi folder only and try to rebuild the project. It will work.

Upvotes: 1

Lenoarod
Lenoarod

Reputation: 3610

In the old react-native version, when we generate the android APK, sometimes the bundle is old, we have to generate it by ourself.
In the react-native 0.61, I find the problem is dismissed. In the old version, firstly you should add the following script to the package.json

"scripts":{
...
"bundle-android": "react-native bundle --entry-file index.js  --platform android --dev false --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./android/app/src/main/res",
...
}

the when you generate the apk , you firstly run the follwing script in the termail to generate the new bundle

npm run bundle-android

when the bundle outputs successfully, then go into the android directory and assemble the APK

cd android

./gradlew assembleRelease

Upvotes: 6

Related Questions