React-native-i18n: Not linked correctly on Android

Created on 21 Jan 2018  路  10Comments  路  Source: AlexanderZaytsev/react-native-i18n

Hi,

Everything is working correctly on iOS but I get the warning message 'react-native-i18n module is not correctly linked' on Android.
I manually checked the result of:

const { NativeModules } = require('react-native');
const { RNI18n } = NativeModules;
console.log(RNI18n);

And it gave 'undefined'.

First I used react-native link to link the lib, after reading a few issue, I followed the manual install instructions. But it seems that all steps were already done by the auto link.

Here is the different files impacted by the manual install:
./android/settings.gradle

rootProject.name = '**'
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
include ':react-native-i18n'
project(':react-native-i18n').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-i18n/android')
include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/android/app')
include ':app'

./android/app/build.gradle

dependencies {
    compile project(':react-native-vector-icons')
    compile project(':react-native-i18n')
    compile project(':react-native-navigation')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:25.0.1"
    compile "com.facebook.react:react-native:+" 
}

MainApplication.java

import com.AlexanderZaytsev.RNI18n.RNI18nPackage;
// ...
protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new VectorIconsPackage(),
            new RNI18nPackage(),
          new NavigationReactPackage()
      );
    }

"react-native": "0.50.3",
"react-native-i18n": "^2.0.10",

Any idea ?
Thanks

Most helpful comment

I get the same error trying it with expo. Thrown Exception is

`react-native-i18n module is not correctly linked

  • node_modules/react-native-i18n/index.js:11:15 in
  • node_modules/metro-bundler/src/Resolver/polyfills/require.js:191:12 in loadModuleImplementation src/Util/i18n.js:4:0 in
  • node_modules/metro-bundler/src/Resolver/polyfills/require.js:191:12 in loadModuleImplementation src/Components/home.js:6:0 in
  • node_modules/metro-bundler/src/Resolver/polyfills/require.js:191:12 in loadModuleImplementation src/Navigation/navigationStack.js:3:0 in
  • node_modules/metro-bundler/src/Resolver/polyfills/require.js:191:12 in loadModuleImplementation src/Reducers/navigationReducer.js:1:0 in `

All 10 comments

have you tried cleaning the build ?
sometimes cd android && ./gradlew clean && cd ../ && react-native run-android is the answer.

I just tried, with no luck.. I still got the same warning message in the console, but thanks for the advice anyway !

+1, having the same issue here, cleaning didn't help for me either

:react-native-i18n:compileDebugJavaWithJavac
Note: /Users/User/Desktop/project/git/project-app/node_modules/react-native-i18n/android/src/main/java/com/AlexanderZaytsev/RNI18n/RNI18nModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

Do you know how to recompile with -Xlint option in Android?

I get the same error trying it with expo. Thrown Exception is

`react-native-i18n module is not correctly linked

  • node_modules/react-native-i18n/index.js:11:15 in
  • node_modules/metro-bundler/src/Resolver/polyfills/require.js:191:12 in loadModuleImplementation src/Util/i18n.js:4:0 in
  • node_modules/metro-bundler/src/Resolver/polyfills/require.js:191:12 in loadModuleImplementation src/Components/home.js:6:0 in
  • node_modules/metro-bundler/src/Resolver/polyfills/require.js:191:12 in loadModuleImplementation src/Navigation/navigationStack.js:3:0 in
  • node_modules/metro-bundler/src/Resolver/polyfills/require.js:191:12 in loadModuleImplementation src/Reducers/navigationReducer.js:1:0 in `

Has anyone had luck fixing this? I'm using Expo and the error log is not pretty to see with every reload.

I looked at the stacktrace:

react-native-i18n module is not correctly linked
**- node_modules/react-native-i18n/index.js:11:15 in <unknown>**
- node_modules/metro-bundler/src/Resolver/polyfills/require.js:191:12 in loadModuleImplementation

I looked at the area referenced by that second line. Index.js does this:

if (typeof RNI18n !== 'undefined') {
  I18nJs.locale = RNI18n.languages[0];
} else if (__DEV__) {
  console.warn('react-native-i18n module is not correctly linked');
}

So how do we set the typeof RNI18n to be not undefined? And is that the desired type?

if you are using Expo, I will suggest to use "ex-react-native-i18n".
In my case it will work.

Guys, Expo does not handle native packages (except if you are using expokit)

Just use https://docs.expo.io/versions/latest/sdk/util.html to get the device language and i18n-js directly.

You will have exactly the same API :)

For my part, except compile project(':react-native-i18n') missing under _dependencies_ from android/app/build.gradle (and thus couldn't resolve the RNI18nPackage symbol), everything was linked correctly

react-native: 0.53.0
react-native-i18n: ^2.0.12

Experiencing the same warning without Expo, any solutions?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vonovak picture vonovak  路  7Comments

tregismoreira picture tregismoreira  路  7Comments

mekaVR picture mekaVR  路  5Comments

sibelius picture sibelius  路  4Comments

AhsanAk picture AhsanAk  路  3Comments