I'm trying to call Facebook app events in my flutter project.
I'm using the dependency facebook_app_events: ^0.12.0.
meta-data is also added in the manifest file.
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
void callFBEvent() async {
try {
var i = await facebookAppEvents.getAnonymousId();
await facebookAppEvents.setAdvertiserTracking(enabled: true);
await facebookAppEvents.logEvent(
name: "User_Selection_Screen", parameters: {
"User_Selection": "User_Selection",
});
print("facebook event success User_Selection_Screen");
}catch(e){
print(e);
}
}
Getting below error
kotlin.UninitializedPropertyAccessException: lateinit property anonymousId has not been initialized
at id.oddbit.flutter.facebook_app_events.FacebookAppEventsPlugin.handleGetAnonymousId(FacebookAppEventsPlugin.kt:82)
at id.oddbit.flutter.facebook_app_events.FacebookAppEventsPlugin.onMethodCall(FacebookAppEventsPlugin.kt:55)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:84)
at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:822)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:336)
at android.os.Looper.loop(Looper.java:174)
at android.app.ActivityThread.main(ActivityThread.java:7386)
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:980)
I open the project in an android module. Then just clean the build of the project first and then just build and sync the Gradle in the android module. then the issue was solved. But I already use pub get lots of time before that but that didn't work. fine, my issue was solved.
In my case the problem was that I inserted the the meta data under actvity tag instead of inserting that under application tag
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
So the solution was basically to put the :
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
<meta-data android:name="com.facebook.sdk.ClientToken"
android:value="#string/facebook_client_token"/>
in the right spot , they need to be under the application Tag , in the first range so not under appliction and then activity tag just under the application tag in the androidManifest just as in the pic below !
enter image description here
Related
I am working on a legacy ionic-cordova project, running my android app on API level 31 (upgraded recently).
I have android:requestLegacyExternalStorage="true" and the permissions
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
on my AndroidManifest.xml file. Also checked my permissions with 'cordova-plugin-android-permissions' and also 'cordova-diagnostic-plugin' for 'READ_EXTERNAL_STORAGE' & 'WRITE_EXTERNAL_STORAGE' permissions and got granted: true,
But I still can not use the 'cordova-plugin-zip', due to EACCES (Permission denied),
this is the error I get on Android Studio:
2023-01-11 13:06:36.328 14977-22760/es.my-app.my-app E/Zip: An error occurred while unzipping.
java.io.FileNotFoundException: /storage/emulated/0/Download/some-file.KMZ: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:492)
at java.io.FileInputStream.<init>(FileInputStream.java:160)
at java.io.FileInputStream.<init>(FileInputStream.java:115)
at org.apache.cordova.CordovaResourceApi.openForRead(CordovaResourceApi.java:250)
at org.apache.cordova.CordovaResourceApi.openForRead(CordovaResourceApi.java:233)
at org.apache.cordova.Zip.unzipSync(Zip.java:84)
at org.apache.cordova.Zip.access$000(Zip.java:23)
at org.apache.cordova.Zip$1.run(Zip.java:39)
Previews to the update, the Zip.unzip method from '#ionic-native/zip' used to work fine to decompress my .kmz files, but now it throws an error: -1 due to permissions denied while trying to read from the External Storage.
Finally, I came up with an OK solution, starting from API 31, to have full access to the external storage there is a particular permission: 'MANAGE_EXTERNAL_STORAGE', in order to register my app for that permission, firstly I had to add it to the 'config.xml' file like so:
<widget xmlns:android="http://schemas.android.com/apk/res/android">
<platform name="android">
...
<config-file parent="/manifest" target="AndroidManifest.xml">
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
</config-file>
...
</platform>
</widget>
it is important to add xmlns:android="http://schemas.android.com/apk/res/android" at the widget tag.
Then to request the 'MANAGE_EXTERNAL_STORAGE' permission I modified the .java file of the plugin on android studion like so:
...
public class FileChooser extends CordovaPlugin {
#Override
public boolean execute(String action, JSONArray inputs, CallbackContext callbackContext) throws JSONException {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R && !android.os.Environment.isExternalStorageManager()) {
try {
Intent intent = new Intent();
intent.setAction(android.provider.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
Uri uri = Uri.fromParts("package", cordova.getContext().getPackageName(), null);
intent.setData(uri);
cordova.getActivity().startActivity(intent);
} catch (Exception e) {
Intent intent = new Intent();
intent.setAction(android.provider.Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
cordova.getActivity().startActivity(intent);
}
}
.... plugin code ...
}
}
The execute function is the starting point of execution for the plugin, there, I added the code that requests permission before executing the rest of the plugin processes...
NOTE: with the newer scoped stotage restrictions for android the 'MANAGE_EXTERNAL_STORAGE' permission might make it hard to publish your app on play store, there are other, more complex, strategies to access the external storage that will not cause that trouble.
can someone help me. I added Google Admob to my Flutter project and did everything according to the instructions. Now I get the following error message with the emulator.I haven't found anything in other forums.
PlatformException (PlatformException(error, Content URL must be non-empty., null, java.lang.IllegalArgumentException: Content URL must be non-empty.
at com.google.android.gms.common.internal.Preconditions.checkNotEmpty(com.google.android.gms:play-services-basement##17.6.0:4)
at com.google.android.gms.ads.AdRequest$Builder.setContentUrl(com.google.android.gms:play-services-ads-lite##20.1.0:2)
at io.flutter.plugins.googlemobileads.FlutterAdRequest.asAdRequest(FlutterAdRequest.java:68)
at io.flutter.plugins.googlemobileads.FlutterInterstitialAd.load(FlutterInterstitialAd.java:53)
at io.flutter.plugins.googlemobileads.GoogleMobileAdsPlugin.onMethodCall(GoogleMobileAdsPlugin.java:304)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:136)
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)
I solve the Problem with the follow things:
classpath 'com.google.gms:google-services:4.3.8'
and
compileSdkVersion 30
minSdkVersion 21
targetSdkVersion 30
My flutter application keeps on crashing and logging this error on firebase crash analytics
Fatal Exception: java.lang.RuntimeException: Unable to destroy activity {com.aims.covidsurvey/com.example.app.MainActivity}: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter activity
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4463)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4482)
at android.app.ActivityThread.-wrap6(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1640)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6617)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
Have tried to debug the app, am not getting much information what is causing the error, anyone know what could be causing this and how to fix it? Have tried to research am not getting much information
the Kotlin code generated by the app
package com.example.app
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
And another crash error
Caused by java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter activity
at com.lyokone.location.FlutterLocationService.setActivity(FlutterLocationService.kt)
at com.lyokone.location.LocationPlugin.deinitialize(LocationPlugin.java:121)
at com.lyokone.location.LocationPlugin.detachActivity(LocationPlugin.java:56)
at com.lyokone.location.LocationPlugin.onDetachedFromActivity(LocationPlugin.java:69)
at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.detachFromActivity(FlutterEngineConnectionRegistry.java:389)
at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onDetach(FlutterActivityAndFragmentDelegate.java:556)
at io.flutter.embedding.android.FlutterActivity.release(FlutterActivity.java:587)
at io.flutter.embedding.android.FlutterActivity.onDestroy(FlutterActivity.java:608)
at android.app.Activity.performDestroy(Activity.java:7136)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1158)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4450)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4482)
at android.app.ActivityThread.-wrap6(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1640)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6617)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
My solution was to change the component location to geolocator
https://pub.dev/packages/geolocator
I've been using firebase services for quite some time.
So i started a new flutter project yesterday and i'm experiencing app crashes, some times when when a user registers an account With Firebase Auth. according to console log, its probably because of invoking onAuthStateChanged.
Can anyone help me resolve this.
NB: Sometimes an account is created successfully without the app crashing.
This is the code where i call onAuthStateChanged :
User _userFromFirebase(FirebaseUser user){
return user != null ? User(uid: user.uid, email: user.email, name: user.displayName, phoneNo: user.phoneNumber)
: null ;
}
Stream<User> get user {
return _auth.onAuthStateChanged.map(_userFromFirebase);
}
Below is the debug console output;
D/FirebaseAuth(14930): Notifying id token listeners about user ( VZcLcnr4dJOZgLjFYU3ls96yHK13 ).
D/FirebaseAuth(14930): Notifying auth state listeners about user ( VZcLcnr4dJOZgLjFYU3ls96yHK13 ).
D/AndroidRuntime(14930): Shutting down VM
E/AndroidRuntime(14930): FATAL EXCEPTION: main
E/AndroidRuntime(14930): Process: com.tonnyapps.app3, PID: 14930
E/AndroidRuntime(14930): java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugin.common.MethodChannel.invokeMethod(java.lang.String, java.lang.Object)' on a null object reference
E/AndroidRuntime(14930): at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin$3.onAuthStateChanged(FirebaseAuthPlugin.java:710)
E/AndroidRuntime(14930): at com.google.firebase.auth.zzp.run(com.google.firebase:firebase-auth##19.2.0:3)
E/AndroidRuntime(14930): at android.os.Handler.handleCallback(Handler.java:873)
E/AndroidRuntime(14930): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(14930): at com.google.android.gms.internal.firebase_auth.zzj.dispatchMessage(com.google.firebase:firebase-auth##19.2.0:6)
E/AndroidRuntime(14930): at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime(14930): at android.app.ActivityThread.main(ActivityThread.java:7050)
E/AndroidRuntime(14930): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(14930): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
E/AndroidRuntime(14930): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
I/Process (14930): Sending signal. PID: 14930 SIG: 9
Lost connection to device.
After many efforts tweaking around with the code and updating dependencies to support higher versions of firebase_auth. I was able to upgrade and fix the version of firebase_auth to version 0.20.1, since it was the last non null-safe version.
And Wallah, it worked, this must have been a bug with whatever version i was using. But it was solved with later releases. The users can now create users successfully and proceed with the normal app flow.
So setting firebase_auth: 0.20.1 in the pubspec.yaml, worked for me.
Since, the project is old, I would recommend the best option is updating all the code, and preferably migrating the project to null safety. This should give you more control over the project future development, and also probably fix the bugs you are experiencing with the old code.
when I use last version of 'com.google.android.gms:play-services-ads:19.2.0', I receive an error message. In fact I have performed all the steps as they are in the documentation.
The error message is:
at android.app.ActivityThread.installProvider(ActivityThread.java:5814)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5403)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5342)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
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:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.IllegalStateException:
******************************************************************************
* Invalid application ID. Follow instructions here: *
* https://googlemobileadssdk.page.link/admob-android-update-manifest *
* to find your app ID. *
******************************************************************************
at com.google.android.gms.internal.ads.zzyz.attachInfo(com.google.android.gms:play-services-ads-lite##19.2.0:24)
at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(com.google.android.gms:play-services-ads-lite##19.2.0:3)
at android.app.ActivityThread.installProvider(ActivityThread.java:5811)
... 10 more
You have to declare your admob application_id in project's manifest XML file like this:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="#string/your_ad_app_id" />
Firstly, you need to get value for APPLICATION_ID from your Google Admob account and put it on AndroidManifest.xml as below correctly. Your account value starts with "ca-app-pub- *** "
<manifest>
<application>
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
</application>
</manifest>
<manifest>
<application
android:name="com.google.android.gms.permission.AD_ID">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy " />
</application>
</manifest>