TypeError: Cannot read property 'brand' of undefined
See original GitHub issueHey guys, when i installed react-native-device-info
with default option, i imported the package and wrote console.log(DeviceInfo.getBrand());
for test. but unfortunately got the same error like subject of this issue.
What should i do ?
Thanks in advance
Summary
Requirements | |
---|---|
react-native-device-info Version | 0.20 |
OS | Android |
OS Version | 7 |
React-native Version | 0.51 |
Navigator Package ? | React-Native-Navigation ( wix ) |
Use which linking package method ? | Both manual and automatic |
Current behavior
TypeError: Cannot read property ‘brand’ of undefined
This error is located at: in AuthPage (created by Connect(AuthPage)) in Connect(AuthPage) (at Navigation.js:83) in Provider (at Navigation.js:82) in _class2 (at renderApplication.js:35) in RCTView (at View.js:112) in View (at AppContainer.js:102) in RCTView (at View.js:112) in View (at AppContainer.js:122) in AppContainer (at renderApplication.js:34)
Code :
import DeviceInfo from ‘react-native-device-info’; … render() { console.log(DeviceInfo.getBrand()); }
Files linked :
MainApplication.java
package com.barberandroid;
import android.app.Application;
import com.reactnativenavigation.NavigationApplication;
import com.facebook.react.ReactApplication;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
//import com.reactnativenavigation.NavigationReactPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends NavigationApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNDeviceInfo(),
new VectorIconsPackage()
);
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
@Override
public boolean isDebug() {
return BuildConfig.DEBUG;
}
@Override
public List<ReactPackage> createAdditionalReactPackages() {
return null;
}
}
setting.gradle
rootProject.name = 'barberAndroid'
include ':react-native-device-info'
project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')
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-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/android/app')
include ':app'
Build.gradle
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.barberandroid"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
...
dependencies {
compile project(':react-native-device-info')
compile project(':react-native-vector-icons')
compile project(':react-native-navigation')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:16
Top GitHub Comments
This issue is wrong. To fix this problem add the library to your MainApplication.java: https://github.com/wix/react-native-navigation/issues/2599
Like the original poster, I am using android and linking has been done correctly. Also, NOT using expo.
I suggest for all future commenters:
Please do not post that you have fixed it by linking correctly. The problem is that it isn’t fixed (for the rest of us) by linking correctly. Congratulations you are luckily not affected by this issue.
Please do not post that you have fixed it in iOS, this is an android issue. As labelled.