3rd Party Library throws NoClassDefFoundError without giving a class name - debugging

I'm trying to integrate a 3rd party library into an existing application; it compiles and builds with no problems, but during execution gives a java.lang.NoClassDefFoundError.
The problem is that the error comes out of the library to which I don't have the source, and the error doesn't tell me what class couldn't be found.
Is it possible to debug this? Any advice?
(It's a Java 1.4, Eclipse, Ant and Tomcat set-up)

You can install JD-Eclipse (or any other decompiler), fire up your debugger, and step through until you find the error.
The plugin should allow you to step into the third party .class files as if they were attached source (assuming they're not obfuscated).

Related

Can a Xamarin Android bindings library behave like 'compileOnly' in gradle?

I am trying to write a Xamarin Android binding library for a library that is loaded in the app during runtime. When using this library in a normal Android project, you would use "compileOnly".
compileOnly 'de.robv.android.xposed:api:82'
compileOnly 'de.robv.android.xposed:api:82:sources'
From my understanding, "compileOnly" makes the code from the library available for compilation but does not add it to the resulting apk. Meaning it needs to be provided in runtime for the app to work.
When reading the Xamarin binding Build Action docs, "compileOnly" sounds very similar to "InputJar".
Does not embed the .jar into the resulting Bindings Library .DLL. Your Bindings Library .DLL will have a dependency on this .jar at runtime. Use this option when you do not want to include the .jar in your Bindings Library (for example, for licensing reasons). If you use this option, you must ensure that the input .jar is available on the device that runs your app.
However, when compiling my application while using methods provided by the runtime library, I get errors from the generated java code that the packages do not exist.
javac.exe error : error: package de.robv.android.xposed does not exist
javac.exe error : de.robv.android.xposed.IXposedHookLoadPackage
javac.exe error : error: package de.robv.android.xposed.callbacks.XC_LoadPackage does not exist
javac.exe error : public void handleLoadPackage (de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam p0)
error : error: package de.robv.android.xposed.callbacks.XC_LoadPackage does not exist
error : private native void n_handleLoadPackage (de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam p0);
Meaning that the code was not made available during compilation. How can I make sure the code is made available during compilation but not embedded into application?
See my answer at https://stackoverflow.com/a/64973909/4374462
Either using AndroidExternalJavaLibrary or [assembly: Java.Interop.DoNotPackage("ref.jar")].

Xamarin binding for AWS SDK

Summary
When binding a JAR/AAR built on top of aws-java-sdk, do you have to EmbeddedReferenceJar all the libraries below your JAR, down to and including the aws-java-sdk, when down at that low level the AWS SDK for .NET has the functionality.
Are there any Xamarin packages (Xamarin.Forms or Xamarin.Android) that give an out-of-the box authentication UI with Sign-In/Sign-Up buttons for AWS user pools, Google+, Facebook authentication providers ?
Context
I would like to use SignInUI from aws-android-sdk-auth-ui in a Xamarin.Android app, which gives you an out-of-the-box UI for authentication to AWS. I've got the AWS UserPool and AWS IdentityPool setup already.
Unfortunately, the AWS SDK for .NET does not expose the equivalent aws-android-sdk-auth-ui a java package built on top of aws-android-sdk-auth-core (also unavailable in .NET), which is built on top of aws-android-sdk-core and finally aws-java-sdk.
I thought about binding a java library. I would create a Xamarin binding project for aws-android-sdk-auth-ui.aar downloaded from maven Central. I followed the Binding an .AAR tutorial. It builds, but the generated aws-android-sdk-auth-ui.dll file is missing some classes. I opened the dll with Ildasm.exe and in the Com.Amazonaws.Mobile.Auth.UI namespace I only found AuthUIConfiguration and BuildConfig, clearly missing the SignInUI class.
Is it expected that when you build a binding project for an .aar file that references other .jar, the build succeeds but silently does not produce wrapper classes for java classes who reference missing jars? I would have guessed building would succeed AND would include a wrapper for all classes, but a failure would occur at runtime in codepaths that require the missing jar.
Alright, so I added aws-android-sdk-auth-core.jar, aws-android-sdk-core.jar to the bindings project, as EmbeddedReferencedJar. That did not help, the generated dll is also missing the same classes. The build output pasted below does point in the direction of misssing reference jars. See below.
How far do I need to go though, do I also need to embed all the way down to the 80MB aws-java-sdk.jar?
I have the following build output:
1>JARTOXML : warning J2X9001: Couldn't load class com/amazonaws/mobile/auth/ui/SignInActivity : java.lang.NoClassDefFoundError: android/support/v7/app/AppCompatActivity
1>JARTOXML : warning J2X9001: Couldn't load class com/amazonaws/mobile/auth/ui/SignInUI$1 : java.lang.NoClassDefFoundError: com/amazonaws/mobile/auth/core/DefaultSignInResultHandler
1>JARTOXML : warning J2X9001: Couldn't load class com/amazonaws/mobile/auth/ui/SignInActivity$SignInProviderResultHandlerImpl : java.lang.NoClassDefFoundError: com/amazonaws/mobile/auth/core/signin/SignInProviderResultHandler
android/support/v7/app/AppCompatActivity indicates that com.android.support:appcompat isn't found. How are those supposed to bind? In Xamarin.Android these classes are in
Xamarin.Android.Support.v7.AppCompat Nuget package. But the jar does not know it's running in Xamarin.Android. Does that mean I also need to EmbedReferenceJar all the native Android stuff as well? That's a deep rabbit hole...
com/amazonaws/mobile/auth/core/DefaultSignInResultHandler: that one should not error, I did embed aws-android-sdk-auth-core.jar with EmbbededRefenceJar
Update:
Someone referred me to Xamarin.GradleBindings. I haven't tested this yet, but thought I'd share in hopes this can be useful to other readers.

java8 tools.jar annotation processing with apt

As java programmers we have inherited a legacy app which is now being upgraded to java8. The App runs on an embedded jre which is shipped along with our App.
We also ship tools.jar with the App, which is used to:
1) Compile .java files at run time; e.g. com.sun.tools.javac.Main.compile("SomeCustomClass.java"...).
2) Process annotations using the apt tool( package com.sun.mirror.apt); e.g. 'int aptReturnCode = com.sun.tools.apt.Main.process(myAnnotationProcessorFactory...);
Problem is that the apt tool has been removed from tools.jar in java8 -> http://docs.oracle.com/javase/7/docs/technotes/guides/apt/GettingStarted.html#deprecated
and we cannot use some thing like 'JavaCompilerTool compiler = ToolProvider.getSystemJavaCompilerTool()' because we only have access to our embedded jre and no jdk on client systems.
As a workaround we are compiling the SomeCustomClass.java into a jar file externally and then adding it to our app's classpath but its not viable long term as these class's come from the client and can change all the time.
I can think of the following ways around this problem:
1) Ship 2 tools.jar an old one for annotation processing and one java8 for compiling code at run time, but no idea how to avoid any naming conflicts etc.
2) Rework the myAnnotationProcessorFactory code that is using annotation processing to use javax.annotation.* instead of com.sun.tools.apt.* . As this is legacy code it will be quite error prone.
Can you guys think of any other ways around it ?
Many Thanks

Using ActionBar Sherlock with intellij through maven. #style/Theme.Sherlock in AndroidManifest.xml does not match

Just trying the simplest thing to use ActionBar Sherlock in an Android app using IntelliJ 12.
I've read in other post and blogs and people keep dowloading ABS' source and mavenizing it ( complaining ABS on maven is too old). It turns out on maven we can get 4.3.1 now.
Therefore, I am trying to avoid mavenizing ABS again.
So, I created a blank Android app project with a simple Hello, World activity.
Compiled and ran it, just to be sure.
Then, I went to the Project Structure and added the ABS library via Maven (com.actionbarsherlock:actionbarsherlock:4.3.1).
Added it to the Module that represents my app.
Made sure to mark the library as "Provided" in the Module Dependencies.
The whole thing compiles and run.
Of course, as soon as I extend the main activity from SherlockActivity the app crashes. Expected...
So, I open the AndroidManifest.xml and add android:theme="" to the application tag.
To my surprise and pain, #style/Theme.Sherlock... does not auto-complete, and the compiler complains with the dreaded error:
Error: No resource found that matches the given name (at 'theme' with
value '#style/Theme.Sherlock')
So, my question is what did I miss?
Is there a way to ask IntelliJ to load the resources from ABS?
Thanks.
Adding ActionBarShelock as a library (plain jar) will not work, you have to configure it as a Library module in IntelliJ IDEA and then set your main module to depend on it. See this tutorial.

LoadLibraryExW() fails, last error is ERROR_MOD_NOT_FOUND, but no missing dependencies?

A customer is using our dll which is creating a child process which uses an open source library, which ultimately fails because of a call to LoadLibraryExW(), the last error returned is ERROR_MOD_NOT_FOUND. This occurs on WinXP 32-bit, but not on other machines. But we know the correct set of dependencies is installed and even in the same directory.
So we thought naturally, to use Dependency Walker to look for what dependency is missing on that particular machine. Unfortunately it doesn't show any missing, just some delay-load warnings that aren't direct dependencies of the library. In my experience using depends.exe has always revealed what the missing dependency is.
So at this point I've pulled my hair out trying to understand why I'm getting ERROR_MOD_NOT_FOUND if all of the library's dependencies are there? The only other thing that makes this machine unique is it's very secure because it's used by the government, but if we were having an access/permissions issue I'd expect a different type of error code.
I've built a small Win32 executable that does nothing but call LoadLibraryExW() on the said library, when it's run from the same directory as the library is located, it loads the library without issue, on the customer's problematic machine.
One thing is that our product is an ActiveX plugin which launches a child process, the child process calls into the 3rd party library, the 3rd party library has the problematic LoadLibraryExW() call. So maybe why it's failing is the context it's running (e.g. from the browser)?
Use the Profiling option of the Dependency Walker on your application. Possibly the library is trying to resolve some APIs dynamically (using LoadLibrary/GetProcAddress) and this won't show up in the static dependencies.
The best way is to use loader snaps. Basically you use gflags.exe (which is included with windbg) to enable loader snaps; then, run the process with the debugger attached. Loader snaps will enable the loader to print out dbg messages of the process and it will print the failures.
gflags.exe -i yourcode.exe +sls
windbg yourcode.exe
Your dependencies might be present on the system but they could be in a folder that is not part of the search order during LoadLibraryExW().
A SetDllDirectory() or AddDllDirectory() call would ensure that the folder containing the dependencies is searched during the LoadLibraryExW() call

Resources