React native auto linking is not working (RN0.61.5) - react-native

Recently I have upgraded from react-native 0.59.1 to 0.61.5 using the react-native upgrade command. Previously I was using manual linking for some packages and I had removed it using react-native unlink but now it is not working properly when I run on android it builds, but the app only shows the following error
I'm really new to react-native so I don't know what all to share. So if you need more info just ask.
MainApplication.java
import android.app.Application;
import com.facebook.react.ReactApplication;
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 Application implements ReactApplication {
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
);
}
#Override
protected String getJSMainModuleName() {
return "index";
}
};
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
#Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}

There are some problems with auto linking in certain versions of ReactNative. All your packages are linked inside your MainApplication.java file. In your file, it is clearly seen that RNDeviceInfo is missing from the list of the packages and I suspect here that it might cause problems for rest of the third-party modules also. I am just mentioning here how to deal with the RNDeviceInfo module.
Update your source code as:
import android.app.Application;
import com.facebook.react.ReactApplication;
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;
import com.learnium.RNDeviceInfo.RNDeviceInfo; //Add this import
public class MainApplication extends Application implements ReactApplication {
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() //add this dependency in the list
);
}
#Override
protected String getJSMainModuleName() {
return "index";
}
};
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
#Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
Once you resolve this, same issue might raise for other modules. To resolve, just visit their github repositories and go through the manual linking process for android platform.
Hope this helps.

to make sure you have the update for version 0.61.5, check out this React-Native update help link https://react-native-community.github.io/upgrade-helper/.
After that run npm install, try to go to Android folder and run ./gradlew clean for powershell orgradlew clean for cmd.

I think this package (react-native-device-info) is not compatible for v0.6 , for example I couldn't migrate react-native-bluetooth-status without manual linking.
but I checked react-native-device-info and it has been updated 16 days ago , so I guess if you upgrade your package it links automatically.

I recently stumbled across the same issue -> when you look at a newly initialized project you can see that the getPackages() is implemented relying on PackageList(this).getPackages(); instead of having new MainReactPackage() in your list of dependencies.
private final ReactNativeHost mReactNativeHost =
new ReactNativeHost(this) {
#Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
#Override
protected List<ReactPackage> getPackages() {
#SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
return packages;
}
#Override
protected String getJSMainModuleName() {
return "index";
}
};

Related

Compile Java for :react-native-firebase:compileDebugJavaWithJavac 712 ms

//mainapplication.java
package 'com.ruci';
import android.app.Application;
import 'com.facebook.react.ReactApplication';
import io.invertase.firebase.RNFirebasePackage';
import java.util.Arrays;
import java.util.List;
...
public class MainApplication extends Application implements ReactApplication {
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 RNFirebasePackage(),
new RNCWebViewPackage(),
new VectorIconsPackage(),
new RNSharePackage(),
new ReanimatedPackage(),
new RNMail(),
new RNCardViewPackage(),
new RNAdMobPackage(),
new LottiePackage()
);
}
...
#Override
protected String getJSMainModuleName() {
return "index";
}
};
...
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
...
#Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, false);
}
}
You havent described the problem you are facing, you have just posted the error snippet. We cant figure out what and when has happened. Next time be more clear, but as per the error i guess you have error when building apk . Can you try installing the below things and then clean the gradle and try rebuilding it ?
npm install --save-dev jetifier
npx jetify

Error compiling app with react-native-FBSDK after update Android Studio

I use the react-native-FBSDK correctly, but, after that update Android Studio to version 3, I receive this error:
Cannot resolve symbol 'CallbackManager'
This is my MainApplication.java
package com.app.dhsriwvboakzzsyqvpjbdxtqmjrlegfclywhtmcgp;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.sbugert.rnadmob.RNAdMobPackage;
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 com.facebook.CallbackManager;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.FacebookSdk;
import java.util.Arrays;
public class MainApplication extends Application implements ReactApplication {
private static CallbackManager mCallbackManager = CallbackManager.Factory.create();
protected static CallbackManager getCallbackManager() {
return mCallbackManager;
}
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 RNAdMobPackage(),
new VectorIconsPackage(),
new FBSDKPackage(mCallbackManager)
);
}
#Override
protected String getJSMainModuleName() {
return "index";
}
};
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
#Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
I see the question Cannot resolve symbol callbackManager facebook sdk 4.0's lib but I cant resolve my question because I am novice on Android development.

react native maps doenst exist airmap or MapsPackage type error

i have problem in react-native-maps .... pls help me
when i add "MapsPackage()" in mainapplication.java ;
React Native: error: constructor MapsPackage in class MapsPackage cannot be
applied to given types
when i delete "MapsPackage()" in mainapplication.java ;
doesnt work maps and i got error "airmap doenst not exist"
my build gradle ;
dependencies {
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 'com.airbnb.android:react-native-maps:0.6.0'
//compile project(':react-native-maps-lib')
}
my mainapplication.java;
package com.polipoolapp;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.airbnb.android.react.maps.MapsPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication
{
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this)
{
#Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
#Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MapsPackage(),
new MainReactPackage()
);
}
#Override
protected String getJSMainModuleName() {
return "index";
}
};
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
#Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
my mainactivity.java;
package com.polipoolapp; //<- put your app name
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import java.util.Arrays;
import java.util.List;
public class MainActivity extends ReactActivity {
protected String getMainComponentName() {
return "PolipoolApp"; //<- put your app name
}
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
}

react native : You have not accepted the license agreements of the following SDK components

I'm installing fbsdk to my react-native apps, i ran the following commands
npm install react-native-fbsdk#0.6.0 --save
react-native link react-native-fbsdk
After successfully installed i run react-native run-android and i got the following result
Here is my changes
In MainApplication.js
package com.ddc;
import android.app.Application;
import com.facebook.react.ReactApplication;
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 com.facebook.CallbackManager;
import com.facebook.FacebookSdk;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
import com.facebook.appevents.AppEventsLogger;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private static CallbackManager mCallbackManager = CallbackManager.Factory.create();
protected static CallbackManager getCallbackManager() {
return mCallbackManager;
}
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 VectorIconsPackage(),
new FBSDKPackage(mCallbackManager)
);
}
};
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
#Override
public void onCreate() {
super.onCreate();
FacebookSdk.sdkInitialize(getApplicationContext());
// If you want to use AppEventsLogger to log events.
AppEventsLogger.activateApp(this);
}
}
In MainActivity.js
package com.ddc;
import com.facebook.react.ReactActivity;
import android.content.Intent;
public class MainActivity extends ReactActivity {
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
}
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
#Override
protected String getMainComponentName() {
return "DDC";
}
}
After that i modify the build.gradle, because after i run react-native link react-native-fbsdk it doesn't modify the file
repositories {
mavenCentral()
}
dependencies {
compile project(':react-native-vector-icons')
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 'com.facebook.android:facebook-android-sdk:4.+'
}
How can i accept the agreement ?
your ANDROID_HOME variable is not properly set. fix that.
Solution via console using sdkmananger:
yes | sudo sdkmanager --licenses
Source - Automatically accept all SDK licences

react-native-call-receiver error react_native_call_receiver does not exist

I am a starter on react native and wanted to use react-native-call-receiver module for learning how to handle call receiving events
I have followed that npm page, and found that in the "register module" section, the author has instructed to add an import statement and new ReactNativeCallReceiver()
However, the template(as shown below)
public class MainApplication extends Application implements ReactApplication {
#Override
protected List<ReactPackage> getPackages() {
......
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
......
within which the code has to be injected is available only in MainApplication.java and not under MainActivity.java in the path android/app/src/main/java/[your-app-namespace]/
(I guess this must be because of the outdated version of manual compared to react. I am using react native 0.41 and react-native-cli 2.0.1)
So i proceeded with the "import" and the "new" statement inside the class, and ran the application, and i get the following error
c:\Myapp\android\app\src\main\java\com\test_nativebase\MainApplication.java:13: error: package ru.getintime.
react_native_call_receiver does not exist
import ru.getintime.react_native_call_receiver.ReactNativeCallReceiver;
^
C:\Myapp\android\app\src\main\java\com\test_nativebase\MainApplication.java:30: error: cannot find symbol
new ReactNativeCallReceiver()
^
symbol: class ReactNativeCallReceiver
2 errors
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
C:\Myapp\android\app\src\main\java\com\test_nativebase\MainActivity.java
package com.test_nativebase;
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
#Override
protected String getMainComponentName() {
return "Test_NativeBase";
}
}
C:\Myapp\android\app\src\main\java\com\test_nativebase\MainApplication.java
package com.test_nativebase;
import android.app.Application;
import android.util.Log;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import ru.getintime.react_native_call_receiver.ReactNativeCallReceiver;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
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 ReactNativeCallReceiver()
);
}
};
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
#Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
This is what i did:
Double Checked whether the import statement is available
Double Checked whether the module is installed and saved under node_modules
I checked out github link to file an issue, but the link that is given on npm is broken. Can somebody help me sort out this error please ?