Flutter Android App crashes on start when use stripe_payment - android

I am trying to use stripe_payment on my Flutter apps. It works fine on IOS simulators, but the app crashed instantly on Android.
I tried to put the stripe_payment package to a new project, and the app crashed on start as well.
The package version I'm using is: stripe_payment: ^0.0.9
Does anyone know how to use the package properly? Thanks a lot !

In your \android\app\src\main\java\com\example\yourProjectName\MainActivity.java
file you should have code similar to the code below:
package com.example.yourProjectName;
import android.os.Bundle;
//import io.flutter.app.FlutterActivity;
import io.flutter.app.FlutterFragmentActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
//public class MainActivity extends FlutterActivity {
public class MainActivity extends FlutterFragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
In order it works for version ^0.1.0,
include this into your project's android/gradle.properties file
android.useAndroidX=true
android.enableJetifier=true

Use latest dependency
dependencies:
stripe_payment: ^0.1.0
use indentation properly.
then use below to get the dependency inside your project
flutter packages get
and import the dependency inside your page where you are using stripe_payment
import 'package:stripe_payment/stripe_payment.dart';
if imported dependency won't give you any error then you can use stripe_payment without any error

Extend your MainActivity with FlutterFragmentActivity.
Problem Solved..

If you use Flutter with Kotlin, then change the MainActivity.kt file's code to this.
android/app/src/main/kotlin/co/popcrn/app/MainActivity.kt
package YOUR_PACKAGE_NAME
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterFragmentActivity() {
override fun configureFlutterEngine(#NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}

Related

GeneratedPluginRegistrant don't can not be applied - Flutter

When I build my Flutter app, this error shows:
error: incompatible types: MainActivity cannot be converted to FlutterEngine GeneratedPluginRegistrant.registerWith(this);
I went to the github of class and saw the difference: https://github.com/theyakka/fluro/blob/master/example/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java
If I put this in my project, when I build application, my class change automatically for this:
package io.flutter.plugins;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import io.flutter.embedding.engine.FlutterEngine;
/**
* Generated file. Do not edit.
* This file is generated by the Flutter tool based on the
* plugins that support the Android platform.
*/
#Keep
public final class GeneratedPluginRegistrant {
public static void registerWith(#NonNull FlutterEngine flutterEngine) {
}
}
I follow this tutorial:https://www.youtube.com/watch?v=NXuAzXY_KOo
I need to run my app in background to get the current location, but don't works.
You need import the plugin,
import io.flutter.plugin.common.PluginRegistry;
and extend your class with FlutterActivity.

Cannot resolve symbol nullable

Getting cannot resolve symbol nullable error for my program.
#androidx.annotations.Nullable - nullable has redline under it.
package com.singularity.birdjumper;
import android.app.Activity;
import android.os.Bundle;
public class GameActivity extends Activity
{
#Override
protected void onCreate(#androidx.annotation.Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
just add this import statement
import android.support.annotation.Nullable;
For androidx, the import statement should be:
import androidx.annotation.Nullable;
Are you using the AndroidX library?
It would be worth adding them into the app gradle file,
//set the version to latest version
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
There is also a great answer over here for more information on AndroidX and migrating your projects over to it.
Android Studio adds both #androidx.annotation and #android.support.annotation problem
i hava the same problem,
sync project with gradle files or update gradle plug

Using LibVLC in Android application - Unresolved methods

I want to use LibVLC in my Android application.
I added below line to gradle dependencies to use precompiled LibVLC library.
compile 'de.mrmaffen:vlc-android-sdk:3.0.0'
When I use below code i get this error.
Cannot resolve method 'getInstance()'
My initialization code is
mLibVLC = LibVLC.getInstance();
My imports are
import org.videolan.libvlc.EventHandler;
import org.videolan.libvlc.IVideoPlayer;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.MediaList;
and my class definition is
public class VideoActivity extends Activity implements IVideoPlayer
Should i add another definitions to my project to solve this problem?

New->Android application Project created with a lot of errors(Android 6.0)

So when i create a new android application project with ANDROID 6.0 library i instantly get the a lot of errors in the MainActivity code.
Starting with The import android.support.v7.app cannot be resolved
To The method onCreate(Bundle) of type MainActivity must override or implement a supertype method
When i add the appcompat.v7 library obviously Some of the errors related are gone but other are coming instead. Like:
The type android.support.v4.widget.DrawerLayout$DrawerListener cannot be resolved. It is indirectly referenced from required .class files on the package line.
And still The method onCreateOptionsMenu(Menu) of type MainActivity must override or implement a supertype method.
Ok. So add the v4 jar too. Ok. I added it too to the project properties and no errors!
Wait,but when i run the app now I get a ClassNotFoundException.
So what the hell android 6.0???
Thanks for the help.
EDIT
MainActivity.java:
package com.minyan.get.dl;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
The main reason is that Android Studio is the main IDE now.
Eclipse is no longer supported.
I suggest switching to Android Studio.

WebIntent plugin for Phonegap: Cannot find import org.apache.cordova.api.Plugin

I just downloaded the WebIntent plugin for phonegap, but immediately ran into an error when setting it up. The first few lines of WebIntent.java are
import java.util.HashMap;
import java.util.Map;
import org.apache.cordova.DroidGap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.text.Html;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
...
public class WebIntent extends Plugin {
Eclipse recognizes all of these imports except for
org.apache.cordova.api.Plugin
After some research, I discovered that Phonegap 2.0 wants plugins to extend the Plugin class. Phonegap 2.7 wants plugins to extend "CordovaPlugin" instead.
A quick look at the Phonegap github reveals that no class called "Plugin" even exists in that package anymore. This confuses me because the WebIntent github was updated just a few months ago, and it still uses Plugin.
I tried changing Plugin to CordovaPlugin wherever I could find it in the file. Surprisingly, most of the errors vansihed. However, the onNewIntent method still has an error:
#Override
public void onNewIntent(Intent intent) {
if (this.onNewIntentCallback != null) {
PluginResult result = new PluginResult(PluginResult.Status.OK, intent.getDataString());
result.setKeepCallback(true);
this.success(result, this.onNewIntentCallback);
}
}
"success(...)" is not a function in CordovaPlugin and there is no function similar to it.
Can anyone think of a way to solve this problem? Or is there information that I'm missing? (A more up-to-date version of WebIntent would be fantastic, but I can't seem to find one)
Had the same problem upgrading to Phonegap 3.0 and found solution is not only change plugin to CordovaPlugin but also you will need to remove "api" from the import statement.
Change
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
To this:
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
Answer reference: http://devgirl.org/2013/09/05/phonegap-3-0-stuff-you-should-know/
I ran into exactly the same problem.
The issue here is that org.apache.cordova.api.plugin is completely removed as of phonegap-2.7.0 and should be replaced with org.apache.cordova.api.CordovaPlugin.
For more info on how to do this, look at http://simonmacdonald.blogspot.fr/2013/06/why-dont-my-plugins-work-in-phonegap.html.
I followed these instructions and you can find the relevant part of my replacement code for WebIntent.java at https://github.com/phonegap/phonegap-plugins/issues/1047.

Categories

Resources