TypeError: Cannot read property 'brand' of undefined
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
}
Is anybody there ?
I need help to use react-native-device-info.
Hi @blackhair, I don't see anything wrong with your linking even tho I never used NavigationApplication. Did you reset the cache of your packager before re-starting it?
@machour Tnx ro reply my question.
I reseted cache of my packager by npm clean cache and run cd android && ./gradlew clean && cd .. && react-native run-android but dosen't work.
this time, error is :
TypeError: undefined is not an object ( evaluating RNDeviceInfo.brand)
I've been pretty busy lately. I'll try to give this a look as soon as possible. And in the mean time, if anyone wants to fix this, PR are really welcome. (and waaaay more helpful than "+1")
This issue is wrong. To fix this problem add the library to your MainApplication.java: https://github.com/wix/react-native-navigation/issues/2599
Getting the same issue.
Have checked and rechecked all linking has been done (automatically, and then manually x 10)
Have deleted all build dirs (android/build & android/app/build) have deleted node_modules and re-run yarn.
The issue persists. Now looking for other plugins.
^ FYI
Environment: OS: Windows 10 Node: 9.0.0 Yarn: 1.6.0 npm: 6.1.0 Watchman: Not Found Xcode: N/A Android Studio: Version 3.0.0.0 AI-171.4408382
Packages: (wanted => installed) react: ^16.3.1 => 16.4.0 react-native: ^0.55.4 => 0.55.4
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.
I get the same issue. only on android.
using react-native-navigation as well, which make the auto linking wrong, but I did it manually like 15 time..
tried every thing suggested here and on related issues.
unlinked and linked manually in every way possible, cleand cash, reinstalled npm,
nothing helps...
works fine on ios.
is there any solution?
@rakafaProg or @blackhair is your project available online so I can test by myself?
Removed all "+1" and iOS related comments, to make this issue readable again.
@machour I can't uplaod this project, since it is for a private company that wants secrecy, but I can copy here all my settings:
in sttings.gradle:
rootProject.name = 'SmartButler_react'
include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/android/app/')
include ':react-native-splash-screen'
project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android')
include ':app'
include ':react-native-device-info'
project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')
in build.gradle:
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.smartbutler_react"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
lintOptions {
checkReleaseBuilds false
}
}
dependencies {
compile project(':react-native-splash-screen')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile project(':react-native-navigation')
compile project(':react-native-device-info')
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
in MainApplication.java
package com.smartbutler_react;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
import org.devio.rn.splashscreen.SplashScreenReactPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.reactnativenavigation.NavigationApplication;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
//public class MainApplication extends Application implements ReactApplication {
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 RNDeviceInfo(),
new MainReactPackage(),
new SplashScreenReactPackage()
);
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
@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;
}
@Nullable
@Override
public List<ReactPackage> createAdditionalReactPackages() {
return null;
}
}
in AndroidManifest.xml
`
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:theme="@style/AppTheme"
tools:replace="android:allowBackup">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
in my app
import { AsyncStorage, Platform } from 'react-native';
import DeviceInfo from 'react-native-device-info';
import xml2js from 'react-native-xml2js';
export let lastURL = '';
console.log(DeviceInfo.getAPILevel());`
//// ^^ Throws Error!
@rakafaProg hey, e did u solved this question? I'm going crazy...
I know iOS comments were removed, but there are only two search results for this error:
undefined is not an object (evaluating 'RNDeviceInfo.brand')
For anyone that is still running into this issue on iOS, this command fixed it for me:
react-native link
@rakafaProg hey, e did u solved this question? I'm going crazy...
Hi, Sorry for the late response. I didn't solve it...
Gave up on this :( I belive it has somthing to do with the react-native-navigator I am using. as if these two cannot coexist ..
@machour closable - another failure to install correctly, but the library definitely works according to instructions (I just installed it...)