react-native-i18n icon indicating copy to clipboard operation
react-native-i18n copied to clipboard

Not linked correctly on Android

Open edouardpagnier opened this issue 6 years ago • 10 comments

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

edouardpagnier avatar Jan 21 '18 15:01 edouardpagnier

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

rezof avatar Jan 22 '18 11:01 rezof

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

edouardpagnier avatar Jan 22 '18 17:01 edouardpagnier

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

cloeys avatar Feb 01 '18 10:02 cloeys

: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?

NachoJusticia avatar Feb 01 '18 23:02 NachoJusticia

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 `

matthiaw avatar Feb 04 '18 16:02 matthiaw

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?

MeKyleH avatar Mar 09 '18 05:03 MeKyleH

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

Daky avatar Mar 14 '18 06:03 Daky

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 :)

zoontek avatar Mar 19 '18 12:03 zoontek

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

gijosso avatar Mar 27 '18 10:03 gijosso

Experiencing the same warning without Expo, any solutions?

18601673727 avatar Sep 12 '18 10:09 18601673727