//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
Related
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";
}
};
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 ReactNativeOneSignalPackage(),
new MapsPackage(),
new VectorIconsPackage());
}
#Override protected String getJSMainModuleName(){return"index";}
};
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
#Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
//This part is giving error:
#Override
public List<ReactPackage> createAdditionalReactPackages() {
return getPackages();
}
}
Hi there i have a problem with integration onesignal push notification into myapp.
As you see i added necessary codes as documanted. But onesignal is not working and if i add createAdditionalReactPackages it gives error and not building. If i remove that part project building succesfully but onIds not working.
What is wrong i dont understand please help me
Thanks in advance.
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.
We are attempting to implement CodePush from Microsoft App Center. We have managed to get to the point where the application downloads the package, and unpacks it. However, it always ends with the response
Update is invalid - A JS bundle file named "null" could not be found within the downloaded contents. Please check that you are releasing your CodePush updates using the exact same JS bundle file name that was shipped with your app's binary.
react#16.2.0
react-native#0.53.3
react-native-code-push#5.3.2
We've made the changes to the MainApplication.java
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
#NonNull
#Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
and
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
// Add additional packages you require here
// No need to add RnnPackage and MainReactPackage
new ActionSheetPackage(),
new PickerPackage(),
new ReactNativeOneSignalPackage(),
new CodePush(getResources().getString(R.string.reactNativeCodePush_androidDeploymentKey), getApplicationContext(), BuildConfig.DEBUG),
new CalendarEventsPackage()
);
}
In the app code, we call
Navigation.registerComponent(ScreenNames.Landing.id, () => CodePush(codePushOptions)(LandingScreen), store, Provider);
The final logs from code-push debug android
[11:31:37] Awaiting user action.
[11:31:42] Downloading package.
[11:31:43] An unknown error occurred.
[11:31:43] Update is invalid - A JS bundle file named "null" could not be found within the downloaded contents. Please check that you are releasing your CodePush updates using the exact same JS bundle file name that was shipped with your app's binary.
It appears the react-native linker is putting some things in the wrong class
public class MainApplication extends NavigationApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this)
{
#NonNull
#Override
public String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
The override should be on MainApplication, not the ReactNativeHost
public class MainApplication extends NavigationApplication {
#NonNull
#Override
public String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this)
{ /*... */ }
You have to Override it inside the ReactGateway createReactGateway(){} method.
That's works for me.
#Override
protected ReactGateway createReactGateway() {
ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
#Override
protected String getJSMainModuleName() {
return "index";
}
#NonNull
#Override
public String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
};
return new ReactGateway(this, isDebug(), host);
}
Cross-posting from Expo's forums:
I have been having problems trying to get Headless JS task to execute on a detached ExpoKit project (SDK25). I have used the React Native documentation to do this.
I have a broadcast receiver
public class MessageReceivedReceiver extends BroadcastReceiver {
private static final String TAG = "MessageReceivedReceiver";
#Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "onReceive");
if (!isAppOnForeground((context))) {
Log.i(TAG, "Not in foreground");
/**
We will start our service and send extra info about
network connections
**/
Intent serviceIntent = new Intent(context, JSBackgroundService.class);
serviceIntent.putExtras(intent.getExtras());
context.startService(serviceIntent);
HeadlessJsTaskService.acquireWakeLockNow(context);
}
}
...
A HeadlessJS Task Service:
public class JSBackgroundService extends HeadlessJsTaskService {
final static String TAG = "JSBackgroundService";
#Override
protected #Nullable
HeadlessJsTaskConfig getTaskConfig(Intent intent) {
Bundle extras = intent.getExtras();
Log.i(TAG, String.format("getTaskConfig: %s", extras));
if (extras != null) {
return new HeadlessJsTaskConfig(
"Test",
Arguments.fromBundle(extras),
5000, // timeout for the task
false // optional: defines whether or not the task is allowed in foreground. Default is false
);
}
return null;
}
}
My MainApplication implements ReactApplication:
public class MainApplication extends ExpoApplication implements ReactApplication {
private static final String TAG = MainApplication.class.getSimpleName();
private List<ReactPackage> packages = Arrays.<ReactPackage>asList(
// new MainReactPackage(),
new MyReactPackage()
);
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
#Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
#Override
protected List<ReactPackage> getPackages() {
return packages;
}
};
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
…
In App.js I have:
…
import JSBackgroundService from ‘./services/jsbackgroundservice’;
AppRegistry.registerHeadlessTask(‘Test’, () => {console.log(“Got it”); return JSBackgroundService; });
export default class App extends React.Component {
…
And JsBackgroundService:
module.exports = async (e) => {
// do stuff
console.log("Running the background service");
console.log(e);
};
Based on logs I know that getTaskConfig is executed but for some reason, I don’t see anything in the console logs, looks like the javascript never gets executed. I have tried also running the Headless JS in foreground for testing purposes but to no avail.
Does anyone have any ideas what could I be doing wrong?
Any help is appreciated :)