I am running an ejected expo project (Expokit, SDK 36).
I have managed to install the module successfully and my application appears in the list of apps to share to for the specified mime types.
Though when I click my app icon, I get the following error:
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@94102b5
V/FA: onActivityCreated
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.florianwolf.voicekeep, PID: 11585
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.florianwolf.voicekeep/host.exp.exponent.share.ShareActivity}: java.lang.ClassCastException: host.exp.exponent.MainApplication cannot be cast to com.facebook.react.ReactApplication
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassCastException: host.exp.exponent.MainApplication cannot be cast to com.facebook.react.ReactApplication
at com.facebook.react.ReactActivityDelegate.getReactNativeHost(ReactActivityDelegate.java:61)
at com.facebook.react.ReactActivityDelegate.onCreate(ReactActivityDelegate.java:76)
at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:44)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
MainApplication.java:
package host.exp.exponent;
import android.util.Log;
import com.facebook.react.ReactPackage;
import org.unimodules.core.interfaces.Package;
import java.util.Arrays;
import java.util.List;
import expo.loaders.provider.interfaces.AppLoaderPackagesProviderInterface;
import host.exp.exponent.generated.BasePackageList;
import okhttp3.OkHttpClient;
import com.alinz.parkerdan.shareextension.SharePackage;
public class MainApplication extends ExpoApplication implements AppLoaderPackagesProviderInterface<ReactPackage> {
@Override
public boolean isDebug() {
return BuildConfig.DEBUG;
}
// Needed for `react-native link`
public List<ReactPackage> getPackages() {
// debugging message with amother tag:
Log.d("GetPackages","reached");
return Arrays.<ReactPackage>asList(
// Add your own packages here!
// TODO: add native modules!
// Needed for `react-native link`
// new MainReactPackage(),
new SharePackage()
);
}
public List<Package> getExpoPackages() {
return new BasePackageList().getPackageList();
}
@Override
public String gcmSenderId() {
return getString(R.string.gcm_defaultSenderId);
}
public static OkHttpClient.Builder okHttpClientBuilder(OkHttpClient.Builder builder) {
// Customize/override OkHttp client here
return builder;
}
}
MainActivity.java:
package host.exp.exponent;
import android.os.Bundle;
import com.facebook.react.ReactPackage;
import org.unimodules.core.interfaces.Package;
import java.util.List;
import host.exp.exponent.experience.DetachActivity;
import host.exp.exponent.generated.DetachBuildConstants;
public class MainActivity extends DetachActivity {
@Override
public String publishedUrl() {
return "exp://exp.host/@flodox/voice-keep";
}
@Override
public String developmentUrl() {
return DetachBuildConstants.DEVELOPMENT_URL;
}
@Override
public List<ReactPackage> reactPackages() {
return ((MainApplication) getApplication()).getPackages();
}
@Override
public List<Package> expoPackages() {
return ((MainApplication) getApplication()).getExpoPackages();
}
@Override
public boolean isDebug() {
return BuildConfig.DEBUG;
}
@Override
public Bundle initialProps(Bundle expBundle) {
// Add extra initialProps here
return expBundle;
}
}
ShareApplication.java:
// your package you defined in ShareActivity
package host.exp.exponent.share;
// import build config
//import com.sample1.BuildConfig;
import com.alinz.parkerdan.shareextension.SharePackage;
import android.app.Application;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactPackage;
import java.util.Arrays;
import java.util.List;
public class ShareApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return false;
//return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new SharePackage()
);
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
ShareActivity.java:
// define your share project, if your main project is com.sample1, then com.sample1.share makes sense....
package host.exp.exponent.share;
// import ReactActivity
import com.facebook.react.ReactActivity;
public class ShareActivity extends ReactActivity {
@Override
protected String getMainComponentName() {
// this is the name AppRegistry will use to launch the Share View
return "MyShareEx";
}
}
Index.js:
The problem might be related to the index.js, which was not automatically created for me after ejecting from Expo, Thus I created my own index.js in the root folder where App,js is located and inserted the following, exactly as stated in the installation instructions (note that prior to the installation of this module this index.js did not exist and the app ran fine):
//index.android.js
import React from 'react'
import { AppRegistry } from 'react-native'
import App from './app.android'
import Share from './share.android'
AppRegistry.registerComponent('VoiceKeep', () => App)
AppRegistry.registerComponent('MyShareEx', () => Share) // TODO: Replace MyShareEx with my extension name
I am running an ejected expo project (Expokit, SDK 36). I have managed to install the module successfully and my application appears in the list of apps to share to for the specified mime types.
Though when I click my app icon, I get the following error:
MainApplication.java:
MainActivity.java:
ShareApplication.java:
ShareActivity.java:
AndroidManifext.xml
Folder structure:![image](https://user-images.githubusercontent.com/1511848/75170854-0528ed80-572b-11ea-8903-efc482564c71.png)
Index.js: The problem might be related to the index.js, which was not automatically created for me after ejecting from Expo, Thus I created my own index.js in the root folder where App,js is located and inserted the following, exactly as stated in the installation instructions (note that prior to the installation of this module this index.js did not exist and the app ran fine):