java.lang.NoClassDefFoundError on Android 4.4 or lower - android-studio

I've got an Android application that I recently upgraded to the Gradle build system among other things, such as using a newer version of build tools, etc.
My targetSdkVersion is 19, so I should be good to go on Android 4.4 and higher. When I run using a 5.0+ device, all is well; however Android 4.4 always crashes with a java.lang.NoClassDefFoundError error of some sort.
As a test, I removed original class that it complained about missing only to have it crash while pointing at a different class.
The first class that it crashed on was an internal private class in a 3rd party library. After removing that library, it pointed to a internal private class in the app itself.
In summary:
the app runs fine on Android 5.0+. It crashes with java.lang.NoClassDefFoundError on anything less than 5.0.
In tests so far, the NoClassDef always seems to refer to an inner class - this is just based on two tests, so it may not be anything concrete.
Here's my android.manifest file: https://gist.github.com/rscott78/19dd88ccde66172d9332

For what it's worth, this can happen when you enable multi-dex support without adding the correct code in your Application class.
Create a class, have it inherit from Application, then add this override:
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
In your AndroidManifest, add a name attribute to your application tag:
<application name=".MyApplication"

Related

How to use HttpClient in android studio app?

unfortunately this question was closed however it is spot on. Let me go through the steps as I am reproducing a legacy app issue that uses httpclient so switching is not an option YET (6 months out maybe).
create android studio app
try to use Httpclient and as he shows in the post above it is in red
I try to add this line in build.gradle to bring it in as a work around(even though core android also brings it in)
implementation 'org.apache.httpcomponents:httpclient:4.5.13'
Then I get this error in android studio
`httpclient` defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for `httpclient` use `HttpUrlConnection` or `okhttp` instead), or repackaging the library using something like `jarjar`.
Ok, so I am using the wrong version so I run build scan and I see this so I bring this one in instead of the other version (android studio now sees HttpClient and can import it at this point)
I still get the same error though about conflicting android libs.
QUESTION: How do I fix the red in my legacy project and not have this error either?
My best bet seems to ignore the error. Will I have issues that I am not seeing though in the future?

Importing LIBGDX library gdx-backend-android.jar into Android Studio Project

After a hiatus of a couple of years I'm picking up Android development again.
I installed the newest Android Studio(4.1.1) with the latest Android SDK version (Android 11, API 30). After that I created a new project with gdx-setup.
If I add the old java source to my newly generated project I get this error:
error: package com.badlogic.gdx.backends.android does not exist
I'm not sure how to add this jar into the new project. In the Gradle configuration I see mentions of the backend, but it's not available.
I also downloaded the 'gdx-backend-android.jar' from the nightly build and put the jar in the Android library folder, all to no avail.
Does anyone actually know how to correctly add this dependency into my project?
I added the jar but still have an error, don't mind the other errors, I first need to fix the GDX import.
The project dependencies are managed by Gradle, so there is no need for you to directly touch any .jar files at all.
The most likely issue you're facing is that you are trying to use Android-specific classes from the core module, which is platform agnostic.
In a typical libGDX project, you do almost all your game code in the core module so it can easily be compiled for any platform. The code you showed above would be in the android module, but your LiveWallpaperStarter class would be part of core.
Some might say there's no reason to use core at all if you're making a Live Wallpaper, since it can't run on any other platforms besides Android. But there is some advantage in keeping the rendering in core so you can test in a desktop game window, because you can more rapidly compile and run on the desktop. This library has some tools that make it easy to wrap your rendering code in a class that lets you simulate a live wallpaper on desktop, for testing.

Wikitude InjectLocation() in Xamarin Component 5.3.0 for iOS is not working

I am trying to create a simple Wikitude AR Xamarin application with POI functionality. I am using Wikitude component 5.3.0 with iOS 10.2 on iPhone 5S, with Xamarin Studio 6.1.1 and Xamarin iOS 10.0.1.8. I am using MvvmCross to create the PCL library with shared code and trying to create my UIViewController with WTArchitectView. I've created a custom binding for getting location update from myviewmodel. The code for the project is accessible here https://bitbucket.org/ershovd/xamarin-augmented/src.
The problem is that I couldn't get location update and onLocationChanged JS function don't get called. I've setup LocationAlwaysUsageDescription settings and I enable using location information in the app when prompted. I even get location information (latitude, longitude) when debugging. However, when I tried to use InjectLocation() method with specific coordinate info the onLocationChanged handler in JS doesn't get called. Moreover, the IsUsingInjectedLocation on WTArchitectView instance always set to false and doesn't changed to true even when I specify UseInjectedLocation = true;
The similar setup for the Android project works fine, I've attached it as well.
I tried to used official Xamarin example https://github.com/Wikitude/wikitude-xamarin/ but they are outdated. After I upgrade to the latest version and fix some compilation bugs (there is some change in API compare with latest version) it still produce the same results (e.g. onLocationChanged event don't get called and InjectLocation method do nothing.
Did I miss something I need to setup in iOS application for receiving update location update? Why is IsUsingInjectedLocation property always set to false and how can I set it to enabled?
Also, if anybody can provide a working sample of POI at location example for latest Xamarin component version (5.3.0) for iOS this will be very helpful.
Thanks,
The problem was that I pass the wrong enum Wikitude.Architect.WTFeatures value into the method LoadArchitectWorldFromURL. The value which works for me is Wikitude.Architect.WTFeatures.Geo. Here is more detailed answer from wikitude support

NUnit not loading latest version of a Console Application

I am re-writing a console application and trying to use Unit Tests. I'm using NUnit, C#, .NET Framework 4 in Visual Studio 2010 on a Windows 7 PC.
When I change code within the application my unit tests don't pick up the latest changes. I can see that NUnit is reloading but for some reason it's not getting the latest version. The only way to get NUnit to work with the latest version is to remove the reference to the Console app, add it back and compile.
Is there a way to avoid doing this? I think the problem is that the the console app is compiled as an EXE, whereas with most applications I've unit-tested they have tended to be DLLs.
EDIT
I had hoped that this question: Unit Testing a Console Application inside Visual Studio contained the answer. If you look at the accepted answer this was the way I'd been proceeding but my test project wasn't picking up the changes. I've now created a class library and I'm applying my tests to that. My console app will simply load, then call, this class library.
Second Edit
I've now got my code to a stage where I can test functionality and I've noticed the same problem with my console app. Although it 'says' it is referencing the compiled DLL, it only picks up the latest change when I delete and re-attach the reference. So, I'm thinking that the problem isn't necessarily connected to NUnit, rather an issue/quirk with console apps.

strange InvalidCastExceptions from NSObject to NSBundle/NSUserDefaults with mono runtime 2.10.12

I seem to be having some problems after updating Xamarin/Monotouch this morning.
I updated MonoDevelop to 3.06 from whatever version was current and stable 10 days ago (sorry I can't be more specific), and Xamarin Studio to 4.0.2. I've been using MonoDevelop exclusively and have opened Xamarin Studio only now, wondering whether or not I was encountering a MonoDevelop bug.
My current MonoTouch version is:
Xamarin.iOS
Version: 6.2.1.201 (Enterprise Edition)
Hash: ed9807c
Branch:
Build date: 2013-19-03 13:42:59-0400
In either IDE, when running my app in either release or debug mode in the Simulator my app crashes with following InvalidCastExceptions:
System.InvalidCastException: Unable to cast object of type 'MonoTouch.Foundation.NSObject' to type 'MonoTouch.Foundation.NSUserDefaults'.
System.InvalidCastException: Unable to cast object of type 'MonoTouch.Foundation.NSObject' to type 'MonoTouch.Foundation.NSBundle'
These aren't the sort of casts that I'd expect to have fail on me :-)
In any case, the app compiles, transfers and runs correctly on an iPhone 4 with iOS 6.1.2 when built and installed from either Xamarin Studio or MonoDevelop
I've set the runtime target to 2.10.12, 2.10.11 and 2.10.9 (via this new Runtime Target menu option in the menus, even though it's meant to have no effect), and each time the app crashes in the same way.
This is all on code that was working correctly before the update (last week, before I went off to Iceland for a holiday and nobody touched anything while I was gone)
We don't use any third party assemblies; I've cleaned and rebuilt all assemblies but that hasn't helped. I'm about to try to narrow the problem down in a small test solution.
UPDATE 1:
Looking at the assemblies' version numbers in MonoDevelop, I see:
Assembly Version 2.0.5.0, found in /Developer/MonoTouch/usr/lib/mono/2.1
Monotouch has an Assemlby Version of 0.0.0.0.
I created a new MonoTouch project and added the first offending line to its main method:
public class Application
{
static void Main (string[] args)
{
// My real App crashes on this line with an InvalidCastException:
string s = NSUserDefaults.StandardUserDefaults.StringForKey("Login");
UIApplication.Main (args, null, "AppDelegate");
}
}
This ran fine.
UPDATE 2:
After changing the Build Options of the test app to match what we have in our real app, I get the same crash. The build options we have are:
iPhone Build -> General -> Linker Options -> Link All Assemblies
iPhone Build -> Advanced -> Use SGen generational garbage collector
iPhone Build -> Advanced -> Use SGen generational garbage collector -> Use reference counting extension.
Disabling ("Use reference counting extension") allows both the test app and my real app to run without crashing. So the problem seems to lie there.
I've updated to Xamarin Studio 4.0.2 and MonoDevelop 3.0.6
So you updated MonoDevelop 3.0.6 to Xamarin Studio 4.0.2, right ? Sadly that does not tell us exactly which version of MonoTouch/Xamarin.iOS was used before/now.
The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).
Could you edit your question to add this ?
my app crashes with following InvalidCastExceptions:
Do you use pre-built assemblies ? If some were against MonoTouch 6.0.x (or earlier) then the strongname change (in 6.2.x) could result in two different monotouch.dll being loaded - and you won't be able to cast instances between them.
If everything is rebuilt from source (no 3rd party .dll that can't be re-compiled) could you try to make a small sample (e.g. by reducing/commenting parts of your app) to show exactly where this happens ? (if possible edit your question with the source or file a bug report).
I've set the runtime target to 2.10.12, 2.10.11 and 2.10.9
The installed system mono is a requirement to run Xamarin Studio and some tools. However application built by Xamarin.iOS does not depend on the system installed Mono. IOW Xamarin.iOS ships with it's own runtime and SDK libraries (e.g. assemblies).

Resources