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

App crash after card entry complete #83

Closed
scottynoshotty opened this issue Jan 3, 2020 · 13 comments
Closed

App crash after card entry complete #83

scottynoshotty opened this issue Jan 3, 2020 · 13 comments
Labels
question Further information is requested

Comments

@scottynoshotty
Copy link

Hi Square team,

I am trying to use this plugin to process in app payments in my flutter app. I enter the test card details i.e. 411111111111 ... and then hit the save button once all card details are entered. The check mark appears and then the app crashes with the following error:

2020-01-02 21:39:06.053 7470-7470/com.phrasing.grocery_bullet E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.phrasing.grocery_bullet, PID: 7470
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=51789, result=-1, data=Intent { (has extras) }} to activity {com.phrasing.grocery_bullet/com.phrasing.grocery_bullet.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.app.Activity.getResources()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:4845)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.app.Activity.getResources()' on a null object reference
at sqip.flutter.internal.CardEntryModule.readCardEntryCloseExitAnimationDurationMs(CardEntryModule.java:215)
at sqip.flutter.internal.CardEntryModule.access$500(CardEntryModule.java:52)
at sqip.flutter.internal.CardEntryModule$1$1.onResult(CardEntryModule.java:86)
at sqip.flutter.internal.CardEntryModule$1$1.onResult(CardEntryModule.java:73)
at sqip.internal.CardEntryActivity$Companion.onActivityResult(CardEntryActivity.kt:596)
at sqip.CardEntry.handleActivityResult(CardEntry.kt:58)
at sqip.flutter.internal.CardEntryModule$1.onActivityResult(CardEntryModule.java:73)
at io.flutter.embedding.engine.FlutterEnginePluginRegistry$FlutterEngineActivityPluginBinding.onActivityResult(FlutterEnginePluginRegistry.java:634)
at io.flutter.embedding.engine.FlutterEnginePluginRegistry.onActivityResult(FlutterEnginePluginRegistry.java:367)
at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult(FlutterActivityAndFragmentDelegate.java:546)
at io.flutter.embedding.android.FlutterActivity.onActivityResult(FlutterActivity.java:594)
at android.app.Activity.dispatchActivityResult(Activity.java:8110)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4838)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886) 
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:7356) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) ### Describe your question

@scottynoshotty scottynoshotty added the question Further information is requested label Jan 3, 2020
@StephenJosey
Copy link
Contributor

Hey @SamuelKampen thanks for reporting this issue. To help us dig into this, can you confirm if this crash happens 100% of the time? Also, have you turned on any developer settings on your device?

@okenshields
Copy link
Contributor

@SamuelKampen Can you also run flutter doctor and paste the summary?

@scottynoshotty
Copy link
Author

@StephenJosey
Yes it happens 100% of the time. I have developer setting enabled on my device but I am doing my testing on the Android emulator in Android studio.

@okenshields
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Linux, locale en_US.UTF-8)

[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
! Some Android licenses not accepted. To resolve this, run: flutter doctor
--android-licenses
[✓] Android Studio (version 3.5)
[!] IntelliJ IDEA Community Edition (version 2019.1)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] IntelliJ IDEA Community Edition (version 2018.3)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] IntelliJ IDEA Community Edition (version 2019.2)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] VS Code (version 1.39.2)
✗ Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[!] Connected device
! No devices available

! Doctor found issues in 6 categories.

@scottynoshotty
Copy link
Author

Here is a snippet of the code. It is just a shopping cart.

@OverRide
Widget build(BuildContext context) {
_cartModel = Provider.of(context);
return Container(
color: Colors.white,
child: Column(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(32),
child: _CartContents(),
),
),
Divider(height: 10, color: Colors.black),
_CartTotal(),
SizedBox(
width: double.infinity,
child: RaisedButton(
onPressed: () {
_pay();
Map<Item, int> cartItems = _cartModel.getCart();
for (Item item in cartItems.keys) {
int itemCountRequested = cartItems[item];
Firestore.instance.runTransaction((transaction) async {
DocumentSnapshot freshSnap =
await transaction.get(item.reference);
int itemCountAvailable = freshSnap['count'];
int itemCountSent = itemCountAvailable >= itemCountRequested
? itemCountRequested
: itemCountAvailable;
int itemCountRemaining = itemCountAvailable - itemCountSent;
await transaction.update(freshSnap.reference, {
'count': itemCountRemaining,
});
});
}
_cartModel.resetCart();
Scaffold.of(context).showSnackBar(
SnackBar(content: Text('Your items are on the way!!')));
},
child: Text('Buy', style: Theme.of(context).textTheme.display4),
color: Colors.lightGreen,
textColor: Colors.white,
),
),
],
),
);
}

void _pay() {
InAppPayments.setSquareApplicationId('sq0idp-v9L6FHpv4e7iAf315K7UnA');
InAppPayments.startCardEntryFlow(
onCardNonceRequestSuccess: _cardNonceRequestSuccess,
onCardEntryCancel: _cardEntryCancel,
);
}

void _cardNonceRequestSuccess(CardDetails cardDetails) {
print(cardDetails.nonce);
InAppPayments.completeCardEntry(
onCardEntryComplete: _cardEntryComplete,
);
}

void _cardEntryComplete() {}

void _cardEntryCancel() {}

@StephenJosey
Copy link
Contributor

Thanks for the info @SamuelKampen. I think I see the issue - Square doesn't support Flutter 1.12 yet. Google released this new version in December which broke many API changes. They state the following:

Plugins developed exclusively on the new plugins API will not work on older pre-1.12 Android projects. Building a pre-1.12 Android project that uses plugins created after 1.12 will yield a build-time error unless the plugin developer explicitly opted to create a second backward compatible implementation.

Until we upgrade our plugin to support 1.12, you'll need to use an older version of Flutter, unfortunately.

@scottynoshotty
Copy link
Author

Hey Stephen,
Thanks for the response,
I downgraded to flutter 1.11.0 and had the same behavior with the same error.

@ElAlgoritmoDeLaNoche
Copy link

I had the same error I solved it by downloading flutter v1.9.1 + hotfix. 6 / 68587a0 / 23/10/2019 in macOS catalina

@sujeetpaandey
Copy link

sujeetpaandey commented Jan 7, 2020

I am also facing the same issue, tried with both square_in_app_payments: ^1.3.0 and square_in_app_payments: ^1.2.3

I also tried to debug with Android Studio and found below logs in Logcat, making the app gets crashed.

2020-01-07 21:05:19.012 21510-21510/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.in_app_payments, PID: 21510
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=51789, result=0, data=Intent { (has extras) }} to activity {com.example.in_app_payments/com.example.in_app_payments.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.view.ContextThemeWrapper.getResources()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:4053)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4096)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1516)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.view.ContextThemeWrapper.getResources()' on a null object reference
at sqip.flutter.internal.CardEntryModule.readCardEntryCloseExitAnimationDurationMs(CardEntryModule.java:215)

    at sqip.flutter.internal.CardEntryModule.access$500(CardEntryModule.java:52)
    at sqip.flutter.internal.CardEntryModule$1$1.onResult(CardEntryModule.java:86)
    at sqip.flutter.internal.CardEntryModule$1$1.onResult(CardEntryModule.java:73)
    at sqip.internal.CardEntryActivity$Companion.onActivityResult(CardEntryActivity.kt:596)
    at sqip.CardEntry.handleActivityResult(CardEntry.kt:58)
    at sqip.flutter.internal.CardEntryModule$1.onActivityResult(CardEntryModule.java:73)
    at io.flutter.embedding.engine.FlutterEnginePluginRegistry$FlutterEngineActivityPluginBinding.onActivityResult(FlutterEnginePluginRegistry.java:634)
    at io.flutter.embedding.engine.FlutterEnginePluginRegistry.onActivityResult(FlutterEnginePluginRegistry.java:367)
    at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult(FlutterActivityAndFragmentDelegate.java:546)
    at io.flutter.embedding.android.FlutterActivity.onActivityResult(FlutterActivity.java:594)
    at android.app.Activity.dispatchActivityResult(Activity.java:6915)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4049) 

@okenshields
Copy link
Contributor

@SamuelKampen , 1.11 is not official release version of Flutter SDK. Please see https://flutter.dev/docs/development/tools/sdk/releases?tab=macos . v1.9.1 was the previous version.

@sujeetpaandey
Copy link

Thanks, @StephenJosey my issue has been resolved after downgrading the flutter version to on macOS Mojave. I have downgraded to Flutter version 1.9 hotfix.6.

@sujeetpaandey
Copy link

Hey Stephen,
Thanks for the response,
I downgraded to flutter 1.11.0 and had the same behavior with the same error.

Hi @SamuelKampen, I guess you are using Windows, you need to downgrade to version 1.9.

@scottynoshotty
Copy link
Author

Thanks for the advice everyone.

I am on Linux.

I switched to 1.9.1+hotfix.6 and have an error when building the project
e: /usr/local/google/home/scottkampen/AndroidStudioProjects/grocery_bullet/android/app/src/main/kotlin/com/phrasing/grocery_bullet/MainActivity.kt: (10, 48): Type mismatch: inferred type is FlutterEngine but PluginRegistry! was expected Finished with error: Gradle task assembleDebug failed with exit code 1

@scottynoshotty
Copy link
Author

I fixed the above issue by following the instructions here

flutter/flutter#45231

It works now! Thanks everyone.

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

No branches or pull requests

5 participants