-1

I am using a Java Security Provider which throws FailedLoginException from the javax.security.auth.login package. As i am using these provider in my Android App i get the problem that Androids javax.security.auth.login package doesn't have such class, it only has the LoginException, which is the base class for the other ones. Because of that my application is throwing NoClassDefFound whenever the FailedLoginException is thrown.

Is there a way to add this missing standard Java class to my Android App, or to workaround that Error?

Any help is appreciated!

vMysterion
  • 165
  • 3
  • 17
  • Check below https://stackoverflow.com/questions/63488098/adding-standard-java-classes-that-are-missing-in-android/63648481#63648481 – lalit vasan Aug 30 '20 at 08:30

3 Answers3

1

Is there a way to add this missing standard Java class to my Android App, or to workaround that Error?

AFAIK, No and No.

I suspect that the best advice we can give you is:

Don't do your user authentication this way!

Android does not support all of javax.security.**, and in particular it doesn't support the JAAS authentication and authorization framework, which is what you are apparently trying to use.

See:

While it might be possible (in theory) to port JAAS to Android, I haven't found any evidence that anyone has succeeded in doing this.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

NoClassDefFoundError in Java is different from ClassNotFoundException and comes when Java Virtual Machine is not able to find a particular class at runtime which was available at compile time. See: 3 ways to solve java.lang.NoClassDefFoundError in Java J2EE

Check rt.jar in your Android studio project explorer : External Libraries -> <1.8> -> rt.jar -> javax -> security -> auth-> login -> . You can see FailedLoginException exist.

Now check External Libraries -> -> android.jar -> javax -> security -> auth-> login -> . You can see FailedLoginException Not exist.

It means your library compiled by rt.jar and now used with android.jar. In other side, you cannot use rt.jar with an Android application (and somewhat overlaps with android.jar). because it is the runtime library for the desktop JRE, not Android. See : Android Studio - android.jar and rt.jar conflicts

Now to solve your problem you can Get the source code to the external library and rewrite it. See How to use classes from rt.jar in an android application?

I suggest to implement that class yourself with some debug function to avoid other dependent class implementation.

Another way which is not recommended is downloading a jar from here and adding it to your project.

Majid Hajibaba
  • 3,105
  • 6
  • 23
  • 55
  • 1
    `I suggest to implement that class yourself with some debug function to avoid other dependent class implementation.` I would be extremely careful about implementing something in the standard namespace. Less from a technical but from a legal perspective. Remember that these JARs come with licence agreements you agree to. – GhostCat Aug 25 '20 at 14:24
  • Sorry! You right. I forgot License Concerns totally. I will edit it. Thank you. – Majid Hajibaba Aug 25 '20 at 14:26
-1

When any new Android OS is developed, it is shipped with a bunch of Java classes that provide support to the apps requiring those classes to function. Let’s consider the Time API in this case. It was added to the Android API level 26 and hence, the apps using this library will crash on lower API levels such as Marshmallow (API 23).

Here’s when desugaring comes into the picture. It allows lower API levels to work with new Java libraries. We’ll see how it does the trick but before that, let’s fire up Android Studio for a quick demo to make things more clear.

To fix this, we need to enable desugaring in our project using the following steps.

  1. Set Android gradle plugin to 4.0 or higher.
  2. In compile options, enable coreLibraryDesugaringEnabled flag and set Java target & source compatibilities to Java 8.
  3. In compile options, enable coreLibraryDesugaringEnabled flag and set Java target & source compatibilities to Java 8.
  4. Enable multidex (for projects supporting API level 20 or below)
  5. Add the desugaring dependency.
   coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.5'
lalit vasan
  • 450
  • 3
  • 6
  • 1
    This missing class issue can not be solved by enabling java 8 desugaring. As you can see in this support table: https://developer.android.com/studio/write/java8-support-table, there is no javax in there. – francis duvivier Aug 31 '20 at 11:43