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.
This seems to be a somewhat recent problem, and I am honestly not sure which problem is the real issue. Last week, after updating VS2017 and Android Support Libraries, I started getting the error "java.exe has exited with code 2". After searching, it seemed like the consensus was to enable MultiDex. So I did that, and it worked fine on newer phones. But when I tried to compile on a KitKat phone, I started to get missing class exceptions (but only when I logged with Android Monitor, no exceptions in VS).
I followed this link regarding custom application classes. I am using the correct bat file, and the right custom class. Everything still looks fine on 21+, but the old devices still reports that mono.MonoPackageManager is missing.
When I go look at the multidex.keep generated in my debug folder, mono/MonoPackageManager.class is definitely in that file. So I really have no clue.
I generated an APK in order to inspect it with classyshark. I found a couple of interesting things there. My total number of methods is around 30K, so why is multidex even required if the limit is 65K? And also, I noticed that mono/MonoPackageManager is in classes2.dex, despite it being in my multidex.keep file.
Am I missing something obvious, or are there some major bugs in Xamarin.Android lately?
EDIT: Progress kind of made? Ignoring the fact that my project shouldn't even need multidex, I noticed that the multidex.keep file that was generated was only a single line with no spaces or anything. When I modified this file to put each class on a new line, then added that file with the build action MainDexMainDexList, everything works fine. I did not need to re-add the classes that it was previously complaining about. I have tried multiple versions of android build tools (specifically 25.0.2 and 26.0.1) with the same result. I think it is very strange that adding new lines fixes the issue, but the generated file does not have new lines.
I had the exact same issue and resolved it by creating a custom multidex.keep file in my project root folder and adding the following to it:
mono/MonoPackageManager.class
mono/MonoRuntimeProvider.class
mono/MonoPackageManager_Resources.class
mono/android/app/NotifyTimeZoneChanges.class
mono/android/app/ApplicationRegistration.class
This is in addition to any of my actual application classes it was complaining of not finding during runtime. This solved my <21 problems (especially for KitKat(19)).
The build system still creates a multidex.keep file, but that's in addition to my custom one, so it seems to work for me.
For me was combination of multiple solutions i found over the internets:
multidex.keep file in my project root
mono/android/app/ApplicationRegistration.class
mono/android/app/NotifyTimeZoneChanges.class
mono/MonoRuntimeProvider.class
mono/MonoPackageManager.class
mono/MonoPackageManager_Resources.class
manually add to .csproj to all build options
<AndroidEnableMultipleDex>true</AndroidEnableMultipleDex>
<AndroidEnableMultiDex>true</AndroidEnableMultiDex>
add to AndroidManifest.xml android-name attribute
<application android:name="android.support.multidex.MultiDexApplication">.....</application
in MainApplication class in Android folder add Register attribute
[Application]
[Register("android/support/multidex/MultiDexApplication", DoNotGenerateAcw = true)]
public class MainApplication : Application, Application.IActivityLifecycleCallbacks
{ ... }
Add Name to MainActivity
[Activity(Name = "xx.xxx.MainActivity")]
public class MainActivity :
global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{ ... }
I am using appcenter.ms to build Andriod so change mainDexClasses.bat was NOT good solution. I tried THIS but this broke all other Android versions.
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.
EDIT: This problem has not already been resolved in the other suggested SO question
I had a fully working app on the market for over a year, with very few crash reports. Then recently I changed my app into a library, so that it could be included within multiple different "wrapper" projects. This was so that I could easily make different version - free, paid, non-google markets, with/without in-app purchasing etc etc.
The new "library+wrapper" app appeared to work fine. I could run it multiple times, without error. But then a day later (when presumably the OS had closed some or all of the app's activities) I tried to run it and it reported
Unable to instantiate application com.mycompany.mygamelibrary.MyGameApplicationClass: java.lang.ClassNotFoundException: com.mycompany.mygamelibrary.MyGameApplicationClass
The class it failed to find is the first class that runs when the program starts up, MyGameApplicationClass - which extends Application. This class is part of the library.
I suspect something goofy in one of the two manifest files.
The manifest of the wrapper project contains the lines...
<application android:icon="#drawable/mygame_icon"
android:screenOrientation="portrait" android:label="My Game Name"
android:name="com.mycompany.mygamelibrary.MyGameApplicationClass">
Any ideas what could have gone wrong?
EDIT: The library was referenced "the correct way" as defined by yorkw's answer to this SO question.
EDIT: I can not repeat the crash at the moment :-( I don't know what it is the OS does when the app is not used for a day or two.
There are two possibilities. Either you, like me, have a spelling error in your manifest file. Have a co-worker or friend read it to make sure the name is correct. Or you have not referenced the project correctly.
The official document describes how to properly link projects in its documentation.
Why it would first seem to work and later stop working is a bit of a mystery. However, I guess that the VM might still have had the necessary references ready to resolve the classes in the library just fine. A restart of the VM removed all those references and trying to resolve them was unsuccessful.
Update: Regarding the edits in the OP: As you confirm that you have correctly referenced the other project, you can check if the project is included in APK, just to be sure. You can rename and open an APK as any other archive (.rar works fine for me). Sometimes, it happened to me, the project is not correctly included in the APK. A cleaning of your workspace usually remedies the problem and so could a restart of your IDE depending on what you are using. To manually conduct a clean in Eclipse for example, use Project->Clean... or try Android Tools->Fix Project Properties by right-clicking on your project.
As you seem to also have fixed the problem by restarting your device, it could be that the libraries were linked incorrectly. A problem that I have never seen myself but as a very common quote says: "Have you tried turning it off and on again?".
For Android Studio:
Build --> Clean Project
Fixed issue.
Have you tried to make a new subclass of MyGameApplicationClass in your 'main' project and set it in the manifest as Application class?
I had a slew of bugs with Android Studio 3.0 Canary 4 and the way I fixed them was by editing the AndroidManifest.xml by adding in some jibberish to the application name. Then, I clicked build. Obviously, a whole mess of new error messages appeared. I changed the name back to what it should be, built the app, and it just ran.
Sometimes, I just don't know...
EDIT: Just ran into this issue on Android Studio 3.0 Canary 4 on my laptop when switching over. I again went through the same process of changing AndroidManifest.xml file to contain a typo, building, and changing back. That didn't work.
I then noticed that instant run was still enabled. Going into settings (by clicking command + , (comma key)) and typing "instant run", I was able to disable instant run, built the app, and the error of class not found went away.
Summary of Steps to Fix [FOR ME]
Invalidate cache / restart
Clean the project
Manually delete the build folder (need to be in project view for this one)
Make an intentionally errant edit to your AndroidManifest.xml file, build the app, observe the errors, remove the errant edit and build again
Disable instant run
Again, I don't mean to insinuate that this will fix everyone's error, but I have now used some combination of these steps on two different machines (MacOS Sierra) and it has been resolved for me. Hope it helps.
In my case, application id and package were mismatched. This should be same as presented in following images...
AndroidManifest.xml
app/build.gradle
In this case you can see, applicationId and package both are same that is com.mycompany.mygamelibrary
May be its a Build Path Configuration problem.I did the following to solve the issue.
1.Right click on your project and go to Java Build Path.
2.Click on Order and Export tab.
3.Check Android Private Libraries and other 3rd part libraries if you have added.
4.Press ok and clean the project.
I hope it will solve the issue.
Once I had the same error message, but maybe the cause isn't the same.
I did a code and worked for a while, then I wanted to improve it and got the same error and I couldn't run it.
I could fix the problem with
the correct Build Path order (as I can see you've already did this)
I check on the Order and Export tab the android-suppor-v4.jar
and the key was the Android SDK Managert->Upgrade everything and (next) Eclipse->Help->Check for updates.
After I upgraded to the latest android plugin and SDK my app compiled and ran again.
I hope this will help you!
I'm not very sure about this but it might be that your system's debug.keystore license validity has expired as it is valid for only 365 days. You just need to delete the debug.keystore from your computer. The debug.keystore will be generated automatically by Eclipse when you compile your Android App.
Same message seen ... this time it turned out to be different output folders for MyApp/gen and MyApp/src in the Build Path (caused by Maven integration).
Unchecking "Allow output folders for source folders" solved the problem.
I had this issue in an Android application that needed an Application class which was created in wrong path inside the Android Studio project. When I moved the class file to the correct package, it was fixed.
This all Process work for me to solve application class Exception.
Step 1: Open Run(window+R) Search -> Prefetch Remove all file (Some file not Delete)
Step 2: Open Run(window+R) Search -> %temp% Remove all file (Some File not Delete)
Step 3: Open Android Studio -> Build -> Clean Project
OR
Select File > Invalidate Caches / Restart > Invalidate and Restart from Android Studio toolbar.
OR
Close and reopen Android project.
OR
Restart System
I ran into this issue several times and both times it seemed to be caused by some instant run feature.
In my case, deleting the application from the device and then installing it from Android Studio again resolved the issue.
I ran into this problem today. The project runs well for over a year but today it reports this issue, and cannot debug on my testing device.
I fixed it by updating to latest gradle version. Hope this can solve your problem.
I know that there are some similar questions, but no solution helped me.
I am getting a java.lang.NoClassDefFoundError when I try to access an (existing) class
in a self-created .jar from my projectgroup.
This .jar works fine in an normal javaProject but doesn´t work with Android.
But an older version of this .jar worked fine with Android.
I am developing with Eclipse + Android Development Tool - Plugin (Version 21)
I have put the .jar in the Project_Home/libs folder.
There are no errors at compiletime.
Before the exception was thrown, there was some "dalvikvm - could not find class ... referenced from ..." errors.
I think, there could be a problem with the Java Version, because our projectgroup recently started to use Java 7, but I am not sure and have no idea how to fix it.
Thanks a lot for your help.
Rename your lib to libs and update the build path and then try again
I think if the project is compiling fine then we can rule out any error in copying or java buildpath. The only other time i get this error is when my import is wrong in the code. I would suggest you to re-check your import and recreate R.java file.
Make sure that your classes do not have same names as ones already present within Android. Upon building the package, due to "optimization" classes with same names are omitted.
Android libraries are mostly compiled against 1.5. Not all libraries are also present within Android. Your package may depend on some other library that is not present within the system.
Ordinarily I don't want to answer my own question but I hope it will help someone.
I didn't see an other warning (not in Logcat, it was in the console):
"Dx bad class file magic (cafebabe) or version (0033.0000)"
I had found this Warning in an other Stackoverflow question.
I had opened one of the class file from the not working .jar with an HexEditor
and changed the Major-Version-Byte to 0x32 and it worked.
I know this is not a solution, because there could be features from Java 7 in the class,
so the class file no longer work, but it proves that it was a problem with the Java version