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.
Related
This is my MainActivity.java:
package com.drodriguez.my_rents;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
public class MainActivity extends FlutterActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public void configureFlutterEngine(#NonNull FlutterEngine flutterEngine) {
super.configureFlutterEngine(flutterEngine);
// FlutterYodo1Mas.getInstance().build(flutterEngine, this);
}
}
With that line commented it compiles ok but otherwise I get this with no more information:
MainActivity.java:21: error: cannot find symbol
FlutterYodo1Mas.getInstance().build(flutterEngine, this);
^
symbol: variable FlutterYodo1Mas
location: class MainActivity
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
More info: paste.ofcode.org/3bYrZ9afhH7YZWBkGwcTJWk
I tried removing /android/.gradle folder.
FlutterYodo1Mas.java is placed next to the MainActivity. I use Flutter but I don't think it's related to this error since these 2 files are .java
[Updated]
You need to import the package of FlutterYodo1Mas class in MainActivity.java.
import com.example.FlutterYodo1Mas;
On the second file, FlutterYodo1Mas.java, the first line wasn't your project name so you had to specify package com.drodriguez.my_rents;
It is tough to understand your issue without the complete stacktrace/error logs. I would suggest the efficient and simplest way, you can try delete the android folder, and run flutter create -a java . inside your app folder, to regenerate android folder, then merge your codes & configurations. There's no harm of trying, make sure you backup your existing code :)
I recently transferred my Flutter project from one Firebase project registration to a different one. I changed the package name everywhere in my Flutter project and replaced the google-services.json file.
My issue is that whenever I Build by APK, it crashes because there are errors in the android/GeneratedPluginRegistrant.java file. My code for the file is as follows; I have pointed out the errors in the code:
package io.flutter.plugins;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry;
/**
* 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) {
ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine);
//THE FOLLOWING FOUR LINES ALL HAVE ERRORS:
io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.registerWith(shimPluginRegistry.registrarFor("io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin"));
io.flutter.plugins.firebaseauth.FirebaseAuthPlugin.registerWith(shimPluginRegistry.registrarFor("io.flutter.plugins.firebaseauth.FirebaseAuthPlugin"));
flutterEngine.getPlugins().add(new io.flutter.plugins.firebase.core.FirebaseCorePlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.googlesignin.GoogleSignInPlugin());
}
}
The errors are basically saying that they can't resolve the "firebase", "firebaseauth", and "googlesignin" packages.
My APK was building just fine before I transferred my project to a different Firebase account. How do I fix these errors? Has anyone else seen errors like this in their GeneratedPluginRegistrant.java file?
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);
}
}
I am new to developing on Android Studio, my app was running fine until the studio exited abruptly after that the project cannot find any of the libraries imported (in asterisks) like Uri, AppCompatActivity etc to my AppCompatActivity class (I am using Android 2.1.2)
import android.net.*Uri*;
import android.os.*Bundle*;
import android.support.v7.*;
import android.util.*Log*;
import android.view.*View*;
import android.widget.*AdapterView*;
import android.widget.*ListView*;
import com.google.android.gms.appindexing.*Action*;
import com.google.android.gms.appindexing.*AppIndex*;
import com.google.android.gms.common.api.*GoogleApiClient*;
import org.xmlpull.v1.*XmlPullParser*;
import org.xmlpull.v1.*XmlPullParserException*;
import org.xmlpull.v1.*XmlPullParserFactory*;
import java.io.*IOException*;
import java.io.*InputStream*;
import java.util.*ArrayList*;
import java.util.*List*;
public class Menu extends android.support.v7.app.*AppCompatActivity* {
What I have tried uptil now:
checked projectstructure -> app -> dependencies
tried sequencing the libs
com.android.support:appcompat-v7:24.2.1
com.google.android.gms:play-services-appindexing:8.1.0
before junit:junit:4.12
Checked build.gradle and added above 2 dependencies
Clean Project
Build APK
ReBuild Project (many times)
P.S: com.google.android... imports were auto generated with onstart and onstop overrides (no idea why)
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
P.S: My Android Studio is installed in C:/Programfiles and my project is saved in a different location under AndroidStudioProjects folder
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?