I'm new to Xamarin and trying to get OneSignal push notifications working in Android. When running the emulator and I fire a push notification from OneSignal, it comes through successfully on the emulator. However, when I deploy the app via Play Store, and I have the app open, firing a push notification crashes the app with the following error:
java.lang.RuntimeException: Unable to instantiate receiver com.onesignal.GcmBroadcastReceiver: java.lang.ClassNotFoundException: Didn't find class "com.onesignal.GcmBroadcastReceiver" on path: DexPathList[[zip file "/data/app/com.woodfordgroup.whybuycars-Bl5_t81uXklo5mpGZRvJcw==/base.apk"],nativeLibraryDirectories=[/data/app/com.woodfordgroup.whybuycars-Bl5_t81uXklo5mpGZRvJcw==/lib/arm64, /data/app/com.woodfordgroup.whybuycars-Bl5_t81uXklo5mpGZRvJcw==/base.apk!/lib/arm64-v8a, /system/lib64]]
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3432)
at android.app.ActivityThread.access$1400(ActivityThread.java:207)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1712)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6831)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:927)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.onesignal.GcmBroadcastReceiver" on path: DexPathList[[zip file "/data/app/com.woodfordgroup.whybuycars-Bl5_t81uXklo5mpGZRvJcw==/base.apk"],nativeLibraryDirectories=[/data/app/com.woodfordgroup.whybuycars-Bl5_t81uXklo5mpGZRvJcw==/lib/arm64, /data/app/com.woodfordgroup.whybuycars-Bl5_t81uXklo5mpGZRvJcw==/base.apk!/lib/arm64-v8a, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:171)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateReceiver(AppComponentFactory.java:84)
at androidx.core.app.CoreComponentFactory.instantiateReceiver(Unknown Source:0)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3425)
... 8 more
Is this because the OneSignal library is not being included in the release? I've also seen mention of AndroidX or multi-dex issues. Here is the android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="15" android:versionName="1.0" package="com.woodfordgroup.whybuycars" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
<application android:label="WhyBuyCars" android:theme="#style/MainTheme" android:icon="#drawable/whybuycars_icon_512x512">
<provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/file_paths" />
</provider>
<receiver android:name="com.onesignal.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.woodfordgroup.whybuycars" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature android-name="android.hardware.camera" android:required="false" android:glEsVersion="0x00030002" />
<permission android:name="com.woodfordgroup.whybuycars.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.woodfordgroup.whybuycars.permission.C2D_MESSAGE" />
</manifest>
And here are my android project properties (target version is 29):
I also wonder if something went wrong with the inclusion of various libraries while I was installing OneSignal from Nuget. Here is my list of project references:
Add this to the proguard file.
-keep class com.onesignal.** { *; }
Source: See oncky's comment on question.
I had exactly the same issue, I could receive notifications without crash if disabled R8 code shrinker in settings ( or adding <AndroidR8ExtraArguments>--no-tree-shaking</AndroidR8ExtraArguments> after the <AndroidLinkTool>r8</AndroidLinkTool> in android .csproject file).
It seems there's some issue with shrinker for onesignal broadcast receiver class
Related
I'm building a cross platform line of business app on .Net Maui. Everything was working (mostly) fine(ish) until today when I updated the .net core sdk from version 6.0.400-preview.22330.6 to 6.0.400. To my knowledge that is the only thing I have changed.
Now any time I attempt to debug the app, the build succeeds however VS for Mac displays an error message after "Deploying to Device". The Error message is: "Cannot execute "Users/xxxx/src/Mobile/bin/Debug/net6.0-android/Mobile.dll
I can't tell what is causing it. It appears like the all the steps succeed in the "Deploying to Device" window. Zero Errors and Zero warnings.
I have noticed that most of the targets are skipped because "all output files are up-to-date with respect to the input files". Thusly, I have cleaned both from the command line and in VS for Mac with no luck.
Finally, I can run the application in the emulator if I use the command:
dotnet build -t:Run -f:net6.0-android
UPDATE:
I pulled up the VS for Mac Logs and found this:
ERROR [2022-08-15 15:48:19Z]: Error loading android manifest '/Users/xxxx/src/Mobile/obj/Debug/net6.0-android/android/AndroidManifest.xml'
System.ArgumentNullException: Value cannot be null. (Parameter 'versions')
at Xamarin.Android.Tools.AndroidAppManifest.Load(String filename, AndroidVersions versions) in /Users/runner/work/1/s/MonoDevelop.MonoDroid/external/androidtools/external/xamarin-android-tools/src/Xamarin.Android.Tools.AndroidSdk/AndroidAppManifest.cs:line 84
at MonoDevelop.MonoDroid.ProjectSystem.AndroidApplicationManifest..ctor(String manifestFile, AndroidProjectProperties projectProperties) in /Users/runner/work/1/s/MonoDevelop.MonoDroid/MonoDevelop.MonoDroid/ProjectSystem/PropertiesProviders/AndroidApplicationManifest.cs:line 13
at MonoDevelop.MonoDroid.ProjectSystem.AndroidManifestCache.CreateNewManifest(String filename) in /Users/runner/work/1/s/MonoDevelop.MonoDroid/MonoDevelop.MonoDroid/ProjectSystem/PropertiesProviders/AndroidManifestCache.cs:line 33
INFO [2022-08-15 15:48:19Z]: Add-in loaded: DotNetCore.Debugger
INFO [2022-08-15 15:48:19Z]: Add-in loaded: MonoDevelop.Debugger.Soft.AspNet
ERROR [2022-08-15 15:48:19Z]: Cannot execute "/Users/xxxx/src/Mobile/bin/Debug/net6.0-android/Mobile.dll"
So for some reason it appears to be linked to the android manifest not being available in the obj folder. I did check the folder and the manifest is indeed in that location. However, I'm not certain if its a race condition or something that makes the file not there at the time the tooling attempts to load the manifest.
UPDATE 2:
I created a new app just to see if there was something wrong with my current app. Same issue. As requested here is the app manifest located in the obj/Debug/net6.0-android folder of the project. I'm not certain this matters or not, but there is not an app manifest in the bin/Debug/net6.0-android folder.
<?xml version="1.0" encoding="utf-8"?>
<!--
This code was generated by a tool.
It was generated from /Users/xxxx/src/NewTest/Platforms/Android/AndroidManifest.xml
Changes to this file may cause incorrect behavior and will be lost if
the contents are regenerated.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" package="com.companyname.newtest" android:versionName="1.0">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:allowBackup="true" android:icon="#mipmap/appicon" android:roundIcon="#mipmap/appicon_round" android:supportsRtl="true" android:name="crc64035c0982af6367fe.MainApplication" android:label="NewTest" android:debuggable="true" android:extractNativeLibs="true">
<activity android:configChanges="density|orientation|smallestScreenSize|screenLayout|screenSize|uiMode" android:theme="#style/Maui.SplashTheme" android:name="crc64035c0982af6367fe.MainActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:configChanges="orientation|screenSize" android:exported="true" android:name="crc6468b6408a11370c2f.WebAuthenticatorIntermediateActivity" />
<provider android:authorities="com.companyname.newtest.fileProvider" android:exported="false" android:grantUriPermissions="true" android:name="microsoft.maui.essentials.fileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/microsoft_maui_essentials_fileprovider_file_paths" />
</provider>
<receiver android:enabled="true" android:exported="false" android:label="Essentials Connectivity Broadcast Receiver" android:name="crc64e53d2f592022988e.ConnectivityBroadcastReceiver" />
<activity android:configChanges="orientation|screenSize" android:exported="true" android:name="crc64ba438d8f48cf7e75.IntermediateActivity" />
<receiver android:enabled="true" android:exported="false" android:label="Essentials Battery Broadcast Receiver" android:name="crc640a8d9a12ddbf2cf2.BatteryBroadcastReceiver" />
<receiver android:enabled="true" android:exported="false" android:label="Essentials Energy Saver Broadcast Receiver" android:name="crc640a8d9a12ddbf2cf2.EnergySaverBroadcastReceiver" />
<service android:name="crc64396a3fe5f8138e3f.KeepAliveService" />
<provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="1999999999" android:authorities="com.companyname.newtest.mono.MonoRuntimeProvider.__mono_init__" />
</application>
</manifest>
Here is the original app manifest file located in the Platforms/Android directory of the project (the one visible in the solution explorer)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="#mipmap/appicon" android:roundIcon="#mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
UPDATE 3:
I just unpacked the signed app file from the Bin folder and got the contents out of that app manifest.
<?xml version="1.0" encoding="utf-8" standalone="no"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" android:compileSdkVersion="31" android:compileSdkVersionCodename="12" package="com.companyname.newtest" platformBuildVersionCode="31" platformBuildVersionName="12">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:allowBackup="true" android:appComponentFactory="androidx.core.app.CoreComponentFactory" android:debuggable="true" android:extractNativeLibs="true" android:icon="#mipmap/appicon" android:label="NewTest" android:name="crc64035c0982af6367fe.MainApplication" android:roundIcon="#mipmap/appicon_round" android:supportsRtl="true">
<activity android:configChanges="density|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:exported="true" android:name="crc64035c0982af6367fe.MainActivity" android:theme="#style/Maui.SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:configChanges="orientation|screenSize" android:exported="true" android:name="crc6468b6408a11370c2f.WebAuthenticatorIntermediateActivity"/>
<provider android:authorities="com.companyname.newtest.fileProvider" android:exported="false" android:grantUriPermissions="true" android:name="microsoft.maui.essentials.fileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/microsoft_maui_essentials_fileprovider_file_paths"/>
</provider>
<receiver android:enabled="true" android:exported="false" android:label="Essentials Connectivity Broadcast Receiver" android:name="crc64e53d2f592022988e.ConnectivityBroadcastReceiver"/>
<activity android:configChanges="orientation|screenSize" android:exported="true" android:name="crc64ba438d8f48cf7e75.IntermediateActivity"/>
<receiver android:enabled="true" android:exported="false" android:label="Essentials Battery Broadcast Receiver" android:name="crc640a8d9a12ddbf2cf2.BatteryBroadcastReceiver"/>
<receiver android:enabled="true" android:exported="false" android:label="Essentials Energy Saver Broadcast Receiver" android:name="crc640a8d9a12ddbf2cf2.EnergySaverBroadcastReceiver"/>
<service android:name="crc64396a3fe5f8138e3f.KeepAliveService"/>
<provider android:authorities="com.companyname.newtest.mono.MonoRuntimeProvider.__mono_init__" android:exported="false" android:initOrder="1999999999" android:name="mono.MonoRuntimeProvider"/>
<provider android:authorities="com.companyname.newtest.androidx-startup" android:exported="false" android:name="androidx.startup.InitializationProvider">
<meta-data android:name="androidx.emoji2.text.EmojiCompatInitializer" android:value="androidx.startup"/>
<meta-data android:name="androidx.lifecycle.ProcessLifecycleInitializer" android:value="androidx.startup"/>
</provider>
<uses-library android:name="androidx.window.extensions" android:required="false"/>
<uses-library android:name="androidx.window.sidecar" android:required="false"/>
</application>
</manifest>
I wan't to compile my project on Android and I got this following error :
Java.Lang.IncompatibleClassChangeError: 'No static method getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)Landroid/graphics/Typeface; in class Landroid/support/v4/content/res/ResourcesCompat; or its super classes (declaration of 'android.support.v4.content.res.ResourcesCompat' appears in /data/app/Digibois.LogiStock--0DmxMZxf8_3l0NMh1wijQ==/base.apk)'
There is my manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.3.4.0" package="Digibois.LogiStock" android:installLocation="auto">
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:label="LogiStock" android:icon="#drawable/icon"></application>
</manifest>
Im using an emulator with Android 6.0 API 23. I also tried with Android 8.1 API 27.
I tried to search a lot of solution but I found anything about it.
Thank's for your help !
Having a check with whether installing Xamarin.Android.Support.v4 NugetPackage :
In addition , to be sure the environment is no problem with Setting up the Android SDK for Xamarin.Android.
I'm trying to implement the MediaPlugin but I am running into a problem. I have done all steps in the setup instructions and get the following error:
Error: No resource found that matches the given name (at 'resource' with value '#xml/file_paths')
As explained in the setup instructions - in my Android project, I have added a folder inside the Resources-folder, called xml - containing a file called file_paths.xml with the following contents:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="my_images" path="Pictures" />
<external-files-path name="my_movies" path="Movies" />
</paths>
I expect this problem to be related to either the above or the AndroidManifest.xml, so I'll include my complete AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.company.Kvitt" android:installLocation="auto">
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application android:label="Kvitt.Android">
<provider android:name="android.support.v4.content.FileProvider"
android:authorities="com.company.Kvitt.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths"/>
</provider>
</application>
</manifest>
Any help or ideas on how to solve this error are really appreciated!
The res/xml directory should be in the same sub-folder as other Resources; drawable, layout, mipmap-XXX, etc...
Do a clean all / build all just as a double check
Double-check your xml path in the project: Resources/xml/file_paths.xml
After a build, check the build artifacts for the file in obj/Debug/android/res/xml
If the resource file is not in the build artifacts the likely cause is the build action is wrong
Check that the build action on the file is set to AndroidResource
I am developing an App with Google Maps and I have some difficulties in making it run on a Genymotion Emulator (Nexus 5 API 22)
Here's the message I got :
Installing application on device
Deployment failed because of an internal error: Unexpected install output: pkg:
/data/local/tmp/com.companyname.progettocomputergraphics-Signed.apk
Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]
Deployment failed. Internal error.
and thats my android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.progettocomputergraphics">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<permission android:name="com.companyname.progettocomputergraphics.MAPS_RECEIVE" android:protectionLevel="signature" />
<uses-sdk android:targetSdkVersion="22" android:minSdkVersion="15" />
<application android:label="progettocomputergraphics" android:icon="#drawable/Icon">
<meta-data android:name="com.google.android.gsm.version" android:value="#integer/google_play_services_version" />
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="my_API_Key" />
<service android:name=".ItineraryService"></service>
<receiver android:name=".RoutesRecevier" />
<activity android:name=".MapActivity">
<intent-filler>
<category android:name="android.intnet.category.LAUNCHER" />
</intent-filler>
</activity>
<activity android:name=".InfoActivity">
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value="MapActivity" />
</activity>
</application>
</manifest>
Can anyone help me?
I've got the same issue (in my case using App Center Push SDK).
The issue was solved by avoiding uppercase on first letter of application/package name.
The first thing I will try to modify uses-permission tag:
<permission android: name = "com.companyname.progettocomputergraphics.MAPS_RECEIVE" android: ProtectionLevel = "signature" />
In my case I had to use
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyBFdb7p_3FTSQWX-sfOniZmQrsBHnM0Bu.."/>
in manifest
I am trying to get admob to work in my Xamarin Android application but I get the following message when trying to display an add:
"You must have AdActivity declared in AndroidManifest.xml with configChanges"
I ave added the Xamarin google play service to my application.
I am set the java heap size to 1G and build with API level 14
I have googled the error message and most answerspoint to the manifest file that needs to include two entries. I have added the entries but still have the problem.
Any idea what I am doing wrong? Here is my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:installLocation="auto" android:versionName="1.0">
<uses-sdk />
<application android:label="Aftermath">
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
Thanks