question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'brand' of undefined

See original GitHub issue

Hey 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:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:16

github_iconTop GitHub Comments

6reactions
doublexcommented, May 1, 2018

This issue is wrong. To fix this problem add the library to your MainApplication.java: https://github.com/wix/react-native-navigation/issues/2599

3reactions
pstantoncommented, May 29, 2018

Like the original poster, I am using android and linking has been done correctly. Also, NOT using expo.

I suggest for all future commenters:

  1. 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.

  2. Please do not post that you have fixed it in iOS, this is an android issue. As labelled.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property of undefined In
JavaScript TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or...
Read more >
TypeError: Cannot read properties of undefined (reading 'map')
I had the same error and solved it by first asking if the array existed. Example: <Filter> { product.color?.map((c) => ( <FilterColor color ......
Read more >
How to Prevent the Error: Cannot Read Property '0' of Undefined
A guide on how to prevent the error "cannot Read Property '0' of Undefined", covering techniques such as try, catch, using const over...
Read more >
TypeError: Cannot read property 'brand' of undefined #383
Summary. Requirements. react-native-device-info Version, 0.20 · Current behavior. TypeError: Cannot read property 'brand' of undefined. This ...
Read more >
How to Fix TypeError: Cannot read Property 'push' of ...
How to Fix TypeError: Cannot read Property 'push' of Undefined in JavaScript · Calling the method on a variable that was previously set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found