简体   繁体   English

react-native-config 在发布版本中不起作用

[英]react-native-config not working in release builds

I was using react-native-config to support multiple flavours for multiple release builds.我使用 react-native-config 来支持多个版本的多种风格。 I've created multiple .env files also and all the debug builds are able to access it and getting the configs.我还创建了多个 .env 文件,所有调试版本都能够访问它并获取配置。 There is no problem in the debug builds but when it comes to release builds they are not getting the configs from the env file.调试版本没有问题,但是在发布版本时,他们没有从 env 文件中获取配置。 I tried to toast the config and it shows empty string.我试图敬酒配置,它显示空字符串。

This might be mostly problem with Proguard.这可能主要是 Proguard 的问题。

When Proguard is enabled (which it is by default for Android release builds), it can rename the BuildConfig Java class in the minification process and prevent React Native Config from referencing it.当 Proguard 启用时(默认情况下,它是 Android 发布版本的默认设置),它可以在缩小过程中重命名 BuildConfig Java 类并阻止 React Native Config 引用它。 To avoid this, add an exception to android/app/proguard-rules.pro:为避免这种情况,请在android/app/proguard-rules.pro:

-keep class com.mypackage.BuildConfig { *; }

mypackage should match the package value in your app/src/main/AndroidManifest.xml file. mypackage 应该与您的app/src/main/AndroidManifest.xml文件中的包值匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM