Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android ExpoKit: undefined is not an object (evaluating 'RNIapModule.prepare') #46

Closed
brentjanderson opened this issue Mar 1, 2018 · 9 comments

Comments

@brentjanderson
Copy link

Version of react-native-iap

0.2.14

Expected behavior

RNIap.prepareAndroid() prepares android

Actual behavior

Errors out with undefined is not an object (evaluating 'RNIapModule.prepare')

Steps to reproduce the behavior

Running RNIap.prepareAndroid(). I tried creating a fresh-from-scratch ExpoKit project to duplicate the issue, and it actually worked just fine. I've tried a variety of approaches including:

  • Delete and reinstall node_modules
  • Triple checked the manual installation steps with my build
  • It works on iOS

I'm completely confused.

@hyochan
Copy link
Member

hyochan commented Mar 1, 2018

@brentjanderson
Did you link the project properly?
Actually, it won't work in expo project without detaching.

@brentjanderson
Copy link
Author

@dooboolab You're right about expo requiring a detach, which I did. And I have run react-native link react-native-iap several times. I have verified with the manual steps as well, and I can't figure out what the difference is - I tried from a fresh Expo project, detached, installed the module, and it worked fine.

@brentjanderson
Copy link
Author

Also tried unlinking and relinking the project just now, targeting a prod build instead of a debug build, still no dice. Also, thank you for your prompt reply!

@hyochan
Copy link
Member

hyochan commented Mar 2, 2018

@brentjanderson
Don't actually understand why that is happening either because it is not happening in my environment. Also, my understanding from your writing is that

  1. You've succeeded linking from a clean install from clean expo detached app.
  2. However, linking is still having a problem when unlinking and linking again. But this time I feel like you are referring to ios. If so, sharing more resources would be helpful like header search path.

Am I right with above?
I hope you give us more examples of your flow. Because to understand the actual problem, it is hard to guess without looking into any sorts of environment of your project.

Thank you.

@hyochan hyochan closed this as completed Mar 5, 2018
@brentjanderson
Copy link
Author

@dooboolab late reply to your previous message:

  1. I have succeeded linking from a clean install from a clean expo detached app
  2. At one point it was working on Android and iOS. It now only works on iOS, so I am troubleshooting Android

One error that I noticed when starting Android Studio that may be useful:

Unsupported Modules Detected: Compilation is not supported for following modules: react-native-iap. Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project.

I am still baffled by this and will be shipping the iOS version with IAP (Thanks again for this marvelous module) but holding back on the Android IAP until getting this resolved.

@brentjanderson
Copy link
Author

brentjanderson commented Mar 8, 2018

Figured it out. For future reference:

  • Expo Detach produces all the stuff that goes into the android project, including AndroidManifest.xml
  • I modified the AndroidManifest.xml to accommodate deep linking schemes, and in doing so I disabled the .MainActivity section, relying instead on the .LauncherActivity section for deep linking and MAIN and LAUNCHER intent.
  • Because the MainActivity class defines the packages we need, but not LauncherActivity, the RNIap module wouldn't get loaded, leading to the issues.

Now that I am using the MainActivity for running the app, the module is available and all is right with the world.

@dwyanelin
Copy link

@brentjanderson

Sorry, I have no idea about how to modify the AndroidManifest.xml to accommodate deep linking schemes, and how to disable the .MainActivity section, relying instead on the .LauncherActivity section for deep linking and MAIN and LAUNCHER intent.

May i ask how to implement that?

@brentjanderson
Copy link
Author

Here is a snippet from my AndroidManifest.xml file (located in android/app/src/main in my detached ExpoKit project), showing the <application> XML element (which I did not modify), followed by the MainActivity declaration:

<application
    android:name=".MainApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true">

<!-- This is the start of the activity that used to say LauncherActivity -->
    <activity
      android:name=".MainActivity"
      android:exported="true"
      android:launchMode="singleTask"
      android:screenOrientation="portrait"
      android:theme="@android:style/Theme.Translucent.NoTitleBar">
      <intent-filter>
        <data android:scheme="my-app-deep-linking-scheme"/>

        <action android:name="android.intent.action.VIEW"/>

        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
      </intent-filter>

      <intent-filter>
        <data android:scheme="exp123456789abcdefetcetcetc"/>

        <action android:name="android.intent.action.VIEW"/>

        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
      </intent-filter>



      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>

        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
    </activity>

I commented out the section of AndroidManifest.xml a few lines lower that refers to android:name=".MainActivity" since it would seem to me to be conflicting to have two activities like that.

The LauncherActivity is not in use in my project, just the MainActivity.

@dwyanelin
Copy link

@brentjanderson

Thank you very much! I learned how to add deep link scheme, and how to add intent to another activity. I added it into the same intent block. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants