Signed React Native app not loading assets correctly

3.1k views Asked by At

So, I run the app on debug mode with a usb cable, it works fine. Then, I run the release version with a usb cable, it works fine too UNTIL I disconnect it from the phone and restart the app. The app is not able to load assets anymore. I have tried all the ways referenced here and here, but still no help.

When app cannot load the assets, it logs this message:

[Error: Could not fetch data from url http://localhost:8081/assets/src/assets/modelv2.pb?platform=android&hash=889b05962c1b1b35b1c07a84b98bcc63]
      framesToPop: 1,
      code: 'EUNSPECIFIED',
      line: 17119,
      column: 31,
      sourceURL: 'http://localhost:8081/index.delta?platform=android&dev=true&minify=false' }

So, it means it is still trying to grab the assets from the local host packager which is dead. Please help me!

React Native: ^0.55.4

React: ^16.3.1

index.js

import { AppRegistry } from 'react-native';
import App from './App'; 
AppRegistry.registerComponent('TagMosquito', () => App);
2

There are 2 answers

4
Nitish On

If you want to create a Signed APK(Signed apk used for Android APK so I think you want to create a APK) you first need to create a bundle. If you already created it then let me know the command you used and also just share the screenshot of your project structure and it should show your main index file and android assets folder path as well then I will give you the command. For now you just.

If not use below commands.

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/

iOS (It's create bundle it self but if not Please use below command)

react-native bundle --entry-file index.js --platform ios --dev false --bundle-output main.jsbundle

Please let me know if any command not working some then it will need some modification. If it will work you need to check there will be a new file created named main.jsbundle

0
Kumar Parth On

Set shrinkResources to false will work in this case. Gradle can automatically remove resources(unused) on your behalf if you enable shrinkResources in your app's build.gradle file.

release {
            ..
            minifyEnabled true
            shrinkResources false    <-- set this false
            proguardFiles getDefaultProguardFile()
        }