Reputation: 155
I'm implementing stripe payment system in flutter application, I got error
PlatformException (PlatformException(flutter_stripe initialization failed, The plugin failed to initialize:
Your Main Activity class com.example.eres.MainActivity is not a subclass FlutterFragmentActivity.
Please make sure you follow all the steps detailed inside the README: https://github.com/flutter-stripe/flutter_stripe#android
If you continue to have trouble, follow this discussion to get some support https://github.com/flutter-stripe/flutter_stripe/discussions/538, null, null))
when I run app, what can cause this error, I send another files below, error appears in line where await Stripe.instance.applySettings() is, if I delete it I will get same error again
Main.dart - main function
void main() async {
HttpOverrides.global = new MyHttpOverrides();
WidgetsFlutterBinding.ensureInitialized();
Stripe.publishableKey =
"pk_test_51LS4cRFZdZe5rLR6wpNk9gLGUxCtdm8kIaymO3CifwTxihGUdSTyRmIl0ipk4rYMfHTdNVBoBmgLbSpCP6IrCzV500wcxqU1Hv";
await Stripe.instance.applySettings();
runApp(MyApp());
}
pubspec.yaml
name: eres
description: A new Flutter project.
version: 1.0.0+1
environment:
sdk: ">=2.17.1 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
http: ^0.13.4
loading_animation_widget: ^1.2.0+2
provider: ^6.0.3
flutter_switch: ^0.3.2
json_annotation: ^4.6.0
flutter_map: ^2.2.0
latlong2: ^0.8.0
flutter_local_notifications: ^9.7.0
flutter_stripe: ^2.0.1
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
flutter:
uses-material-design: true
assets:
- assets/images/
Android/build.gradle
buildscript {
ext.kotlin_version = '1.5.0'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
if u have any suggestion how to fix this, please comment, thank you very much
Upvotes: 4
Views: 3420
Reputation: 6981
In your android's MainActivity file, it should extend FlutterFragmentActivity.
AppFolder -> Android -> app -> src -> kotlin -> com.xxx.xxx -> MainActivity
class MainActivity : FlutterFragmentActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine)
{
// Your code
}
}
Upvotes: 5