Xamarin Forms, Android - Java.Lang.ClassNotFoundException - android

I'm currently updating a Xamarin Forms App and suddenly experiencing this error on Android:
Exception {Java.Lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.GooglePlayServicesUtil" on path: DexPathList[[zip file "/data/app/com.alphacoreconsulting.tflmetrosound-Ek3U1cNyzLe9Jayp9enzXQ==/base.apk"],nativeLibraryDirectories=[/data/app/c…} Java.Lang.ClassNotFoundException
It triggers on this line:
Xamarin.FormsMaps.Init(this, bundle);
I've researched and I've ensured all packages are the same version:
Please would anyone be able to offer some help on this?
UPDATE:
I have since updated the proguard.cfg file and added this line:
-keep public class com.google.android.gms.common.GooglePlayServicesUtil
After adding this I am now experiencing this error:
no static method "Lcom/google/android/gms/common/GooglePlayServicesUtil;.isGooglePlayServicesAvailable(Landroid/content/Context;)I"

You will see this exception at runtime when code has been stripped from the executable usually by the linker or R8/Proguard. You can provide a configuration file to both tools allowing you to keep code the linker or R8/Proguard think you are not using. These tools are not able to properly detect code you use at runtime via reflection for example.
Here is the documentation for the linker configuration file. Another approach is to use a "LinkerPleaseInclude.cs" file manually referencing the code you do not want to be linked out.
Here is the documentation for the R8/Proguard configuration file.

Related

Unable to instantiate application: Didn't find class on path: DexPathList

One of our Unity applications recently ran into a problem on Android with the Application class not being in the main dex. The result is the application builds, but crashes on launch.
This is an existing Android application, with multidex enabled, and the Application extends MultiDexApplication. I followed the instructions to Declare classes required in the primary DEX file, but the same Exception is thrown.
java.lang.RuntimeException: Unable to instantiate application com.example.Application: java.lang.ClassNotFoundException: Didn't find class "com.example.Application" on path: DexPathList
Similarly, the MultiDexApplication class is not found in the main dex, as seen further in the stack trace:
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.multidex.MultiDexApplication" on path: DexPathList
I have tried
Adding multiDexKeepFile.txt (multiDexKeepFile file('multiDexKeepFile.txt'))
Adding multiDexKeepProguard.pro (multiDexKeepProguard file('multiDexKeepProguard.pro'))
Note: the issue occurs regardless of whether proguard is enabled or disabled.
When I add the multiDexKeep files to Assets/Plugins/Android/, where the gradle file is located, Unity seems to ignore them, even when I export the project. So I have also tried:
Using an IPostprocessBuildWithReport to manually add the multiDexKeep files.
Using an IPreprocessBuildWithReport to manually add the multiDexKeep files.
Making an Android Library that contains the multiDexKeep files.
Unity does not seem to pick up on the multiDexKeep files on its own, but it is able to export them, with either process. However, even when I export the project and build the project in Android Studio, the classes still do not appear in the main dex.
Has anyone solved this issue?
multiDexKeepFile.txt:
androidx/multidex/MultiDexApplication.class
com/example/Application.class
multiDexKeepProguard.pro:
-keep class androidx.multidex.MultiDexApplication
-keep class com.example.Application
I was able to resolve this. It seems that Unity recognizes the files if they are inside an .androidlib.
I also found references to an sdk that we are no longer using inside of the main Activity. Removing the code and the sdk also seems to have appeased the dex gods.

Warning:com.qoppa.viewer.b.h: can't find referenced class android.graphics.PixelXorXfermode

I am getting this warning while i am trying to generate signed APK file.
In my project i used qoppa library to create pdf files. can any one please help me to fix this. Should i need to write anything in my proguard file to fix this?
This error is due to the fact that the class PixelXorXfermode was removed in Android API Level 24:
https://developer.android.com/sdk/api_diff/24/changes/pkg_android.graphics.html
To resolve the issue, download the latest version of qPDF Toolkit 5.6 from Qoppa's website in which this class is no longer used.

xamarin android native library - No Packages Found

A few days ago I was able to create an android bindings library for a particular .jar without issue.
I attempted to make a new library in order to post a question sample on github, now JarToXml won't generate anything:
1>JARTOXML : warning J2X9001: Couldn't load class device/scanner/ScanConst : java.lang.ClassNotFoundException: device.scanner.ScanConst
1>JARTOXML : warning J2X9001: Couldn't load class device/scanner/ScannerService : java.lang.ClassNotFoundException: device.scanner.ScannerService
.... (Same error for all classes in .Jar)
1>BINDINGSGENERATOR : warning BG8601: No packages found.
I'm totally confused because in one project I can generate the bindings, yet in another I can't.
Jar file: https://github.com/mribbons/PM_Scanner/blob/master/device.scanner.jar?raw=true
Turns out the problem was the path of the 2nd binding library project - Java doesn't like #.

Android Studio 0.8.0 with Shinobi Charts

I was trying out the sample code posted for shinobi charts on android studio 0.8.0 from
https://github.com/ShinobiControls/shinobicharts-with-android-studio
I tried to import the shinobicharts jar as an .jar library .
It compiled perfectly , but I kept getting a runtime error and I have no clue what to do.This is the error displayed, the app never opens, just starts out with this crash
java.lang.NoClassDefFoundError: com.shinobicontrols.charts.R$styleable
at com.shinobicontrols.charts.ct.a(SourceFile:850)
It looks like you're running Proguard and it stripped out one or more needed classes.
Try turning off Proguard. If that gets past this problem, then you can turn it back on and fix its configuration file.
To fix it, you'll need to add rules to "keep" classes that it couldn't tell are needed. You can name specific classes or classname patterns. There might be a way to tell it to look at references from the library .jar to classes outside the library.

Class Not Found Exception on device, APP works on emulator

EDIT:
I have a solution for my problem, see below in the answers
I have searched and read all related questions on this issue, but none has worked for me.
I have an app which uses ViewPager Indicator as Library and it has a class application.
The app runs fine on the emulator, but when I try to export as signed apk.
Depending on the answers given for this exception and those which I have tried, it sometimes failed with error "Conversion to Dalvik format failed with error 1" or It exports correctly and crashes on the device.
Something peculiar though, when I run on the emulator, the apk generated is 600kb+ and when i export as signed apk it is around 300kb. It is somehow not referencing the library.
What I tried:
Default settings with only ViewPager referenced as library in the android properties
Adding JARs(ViewPager indicator and support ) in the libs folder
Any help will be much appreciated. Thanks
I found out that the issue was with proguard. If you have a class on the application level you should tell proguard to keep it public.
This is how I did it. I am currently using ADT20, I dont know if it is the same for older versions.
In file: proguard-project.txt
append this line (MyAPP being the class)
-keep public class <MyAPP>
In file: project.properties
uncomment this line
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
More info here:http://developer.android.com/tools/help/proguard.html#configuring

Categories

Resources