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.
Related
i'm trying to use mapbox in reactnative and as documented i follow everything
but my app broking.
please find the below exception for your reference
null is not an object (evaluating 'MapboxGL.StyleURL').
Please help me
I just have this issue and maybe this will help you.
I have followed the official documentation to integrate #react-native-mapbox-gl/maps, but it keeps telling me
null is not an object(evaluating 'MapboxGL.StyleURL')
for version 7.0.8~7.2.0 and
Native part of Mapbox React Native libraries were not registered properly, double check our native installation guides.
after version 8.0.0.
I have added the RCTMGLPackage in the MainApplication:
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() {
#SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
packages.add(new MainReactPackage());
packages.add(new RCTMGLPackage());
return packages;
}
#Override
protected String getJSMainModuleName() {
return "index";
}
};
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
But still not work every time.
After checking the existing code, it has other places to add Native Module package in Activity.
in MainActivity :
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(this.getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModulePath("index")
.addPackage(new MainReactPackage())
.addPackage(new RCTMGLPackage())
.setCurrentActivity(this)
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
Not sure if you have the same case, may this will help you.
//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
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 :)
https://facebook.github.io/react-native/releases/next/docs/headless-js-android.html#headless-js
I can't seem to find the right way to do it
I am running React-native 0.40
I implemented the HeadlessJsTaskService to execute some react native code.
For me the ReactExecutorService just silently failed, because i didn't provide any Extras when calling startService(new Intent(this, MyTaskService.class));. The following code fixes that:
#Override
#Nullable
protected HeadlessJsTaskConfig getTaskConfig(Intent intent) {
Bundle extras = intent.getExtras();
WritableMap data = extras != null ? Arguments.fromBundle(extras) : null;
return new HeadlessJsTaskConfig(
"FeatureExecutor",
data,
5000);
}
I also had an existing Application class, that didn't implement ReactApplication. I had to add some code to make the HeadlessJsTaskService work:
private final ReactNativeHost reactNativeHost = new ReactNativeHost(this) {
#Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
#Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
// Insert your packages, e.g.
new MainReactPackage()
);
}
};
#Override
public ReactNativeHost getReactNativeHost() {
return reactNativeHost;
}
You also have to add your custom service to the manifest. For example:
<service android:name=".MyTaskService"/>
Please provide some additional information about your issues in case the solutions above do not help.