25

My Android APK is running off the JavaScript present when I generated the first signed APK. I've tried cleaning/rebuilding the project in Android Studio, I've tried ./gradlew clean in the android subfolder. Any ideas as to why the code isn't updating? I've seen this issue, without any success for myself.

MattyK14
  • 2,046
  • 2
  • 17
  • 29

10 Answers10

78

I deleted the index.android.* files in android/app/src/main/assets/ directory. Then in the project root, ran

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

Then I regenerated the signed APK and voila!

EDIT: If you are using a newer project, you may not have an index.android.js only index.js. If that's the case, you'll want to change it to:

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
MattyK14
  • 2,046
  • 2
  • 17
  • 29
  • 15
    this must be done every time we submit a new build? Is there a permanent fix? – Avery235 Mar 06 '18 at 10:46
  • @Avery235 yes, you have to bundle the JavaScript for the apk. If you don't bundle for iOS it just uses the packager I believe. Not sure if there's a way to do the same for Android – MattyK14 Mar 06 '18 at 14:40
  • 2
    any idea why I get an error because I don't have an index.android.js? – Roco CTZ Apr 01 '18 at 10:10
  • 3
    As per release 0.49 (september 2017) there is no index.android.js and no index.ios.js. Only index.js (unique file for both of them) – Roco CTZ Apr 01 '18 at 10:18
  • 1
    That was my solution after 3 hours of banging my head at the keyboard... Thanks man – chenop Aug 04 '18 at 06:04
  • @MattyK14 can you please explain why do I always have to run the second line of code in your solution? I now need to run it always before compiling my App – Shubham Bisht Apr 25 '19 at 10:41
  • @ShubhamBisht for development or release? It's necessary for release because you need to bundle the JavaScript. If you have to do it for development, you'll need to configure your device properly to communicate with your packager. – MattyK14 Apr 26 '19 at 19:19
  • 1
    I found that if the old APK is still around, a new one may not get created. So I also do `rm android/app/build/outputs/apk/release/app-*` – RavenMan Jul 10 '19 at 06:45
8

1.Delete (index.android.bundle) files inside directory android/app/src/main/assets.

2.run 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

3.Delete folders (drawable,drawable-hdpi,drawable-mdpi,drawable-xhdpi,drawable-xxhdpi,drawable-xxxhdpi,raw) inside android/app/src/main/res

4.run react-native run-android --variant=release

IF NOT WORKING TRY THIS https://github.com/react-native-community/async-storage/issues/127#issuecomment-502574735

Heartless Vayne
  • 904
  • 1
  • 8
  • 18
2

if you were using EXPO and you have ejected the app, the build process still pass through EXPO's server. In order: from the project root folder publish the changes to EXPO:

expo-cli publish

then, once it is finished, from within the android root folder:

gradle assembleDebug

or

gradle assembleRelease
Jonathan
  • 595
  • 5
  • 10
2

run this in react-native project termanil:

npx 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
1

The below commands worked for me ...

1. cd android

2. gradlew clean

3. gradlew assembleRelease

thanks

1

When i used assembleRelease, it generated older apk.

Adding below config to app/build.gradle

project.ext.react = [
  bundleInRelease: true
]

solved my problem.

Antoine
  • 1,393
  • 4
  • 20
  • 26
1

follow 2 steps only given below:

//firstly make build as Debug.

  1. => ./gradlew assembleDebug

//then make build as Release.

  1. => ./gradlew assembleRelease

it works for many. Thanks

sherkhan
  • 811
  • 8
  • 8
0

I can't comment yet, so instead here's a long automation for Noe Fabellon's suggestion (which worked for me)

From the project root directory

rm android/app/src/main/assets/index.android.bundle && 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 && rm -R android/app/src/main/res/drawable-hdpi android/app/src/main/res/drawable-mdpi android/app/src/main/res/drawable-xhdpi android/app/src/main/res/drawable-xxhdpi android/app/src/main/res/drawable-xxxhdpi android/app/src/main/res/raw || true && cd android && ./gradlew clean && ./gradlew assembleRelease && cd .. && react-native run-android --variant=release
Alita
  • 587
  • 1
  • 6
  • 16
0

cd android gradlew clean goto AwesomeProject\android\app\src\main\assets and delete index.android.bundle file cd.. 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/build/intermediates/res/merged/release/ gradlew assembleRelease

worked for me

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 20 '23 at 10:29
-1

I faced similar issue, if none of the solutions are working for you this one should work:

  1. cd android
  2. gradlew clean
  3. goto AwesomeProject\android\app\src\main\assets and delete index.android.bundle file
  4. cd..
  5. 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/build/intermediates/res/merged/release/
  6. gradlew assembleRelease
rohini
  • 1
  • 1
  • 1