how to fix java.lang.NoClassDefFoundError crash - java

My app is live on play store. Its not crashing in all devices but I can see this crash in a few device only. Please help me to fix this issue.
java.lang.NoClassDefFoundError: Failed resolution of:
Lcom/google/android/gms/auth/api/phone/SmsRetriever; at
com.facebook.accountkit.internal.PhoneLoginController.createSmsToken(PhoneLoginController.java:250)
at
com.facebook.accountkit.internal.PhoneLoginController.logIn(PhoneLoginController.java:188)
at
com.facebook.accountkit.internal.LoginManager.logInWithPhoneNumber(LoginManager.java:372)
at
com.facebook.accountkit.internal.AccountKitController.logInWithPhoneNumber(AccountKitController.java:627)
at
com.facebook.accountkit.ui.PhoneLoginFlowManager.logInWithPhoneNumber(PhoneLoginFlowManager.java:57)
at
com.facebook.accountkit.ui.ActivityPhoneHandler.onPhoneLoginComplete(ActivityPhoneHandler.java:189)
at
com.facebook.accountkit.ui.AccountKitActivity$1.onReceive(AccountKitActivity.java:176)
at
android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:297)
at
android.support.v4.content.LocalBroadcastManager.access$000(LocalBroadcastManager.java:46)
at
android.support.v4.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:116)
at android.os.Handler.dispatchMessage(Handler.java:102) at
android.os.Looper.loop(Looper.java:148) at
android.app.ActivityThread.main(ActivityThread.java:5417) at
java.lang.reflect.Method.invoke(Native Method) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused
by: java.lang.ClassNotFoundException: Didn't find class
"com.google.android.gms.auth.api.phone.SmsRetriever" on path:
DexPathList[[zip file
"/data/app/gharkadabba.gharkadabba-1/base.apk"],nativeLibraryDirectories=[/data/app/gharkadabba.gharkadabba-1/lib/x86,
/vendor/lib, /system/lib]] at
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at
java.lang.ClassLoader.loadClass(ClassLoader.java:469) at
com.facebook.accountkit.internal.PhoneLoginController.createSmsToken(PhoneLoginController.java:250) 
at
com.facebook.accountkit.internal.PhoneLoginController.logIn(PhoneLoginController.java:188) 
at
com.facebook.accountkit.internal.LoginManager.logInWithPhoneNumber(LoginManager.java:372) 
at
com.facebook.accountkit.internal.AccountKitController.logInWithPhoneNumber(AccountKitController.java:627) 
at
com.facebook.accountkit.ui.PhoneLoginFlowManager.logInWithPhoneNumber(PhoneLoginFlowManager.java:57) 
at
com.facebook.accountkit.ui.ActivityPhoneHandler.onPhoneLoginComplete(ActivityPhoneHandler.java:189) 
at
com.facebook.accountkit.ui.AccountKitActivity$1.onReceive(AccountKitActivity.java:176) 
at
android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:297) 
at
android.support.v4.content.LocalBroadcastManager.access$000(LocalBroadcastManager.java:46) 
at
android.support.v4.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:116) 
at android.os.Handler.dispatchMessage(Handler.java:102)  at
android.os.Looper.loop(Looper.java:148)  at
android.app.ActivityThread.main(ActivityThread.java:5417)  at
java.lang.reflect.Method.invoke(Native Method)  at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Suppressed: java.lang.ClassNotFoundException:
com.google.android.gms.auth.api.phone.SmsRetriever at
java.lang.Class.classForName(Native Method) at
java.lang.BootClassLoader.findClass(ClassLoader.java:781) at
java.lang.BootClassLoader.loadClass(ClassLoader.java:841) at
java.lang.ClassLoader.loadClass(ClassLoader.java:504)
Caused by: java.lang.NoClassDefFoundError: Class not found using
the boot class loader; no stack trace available
I can see Moto G (3rd & 4th Gen), One Plus one device having crash.
I added below line to ProGuard file.
-ignorewarnings
-keep class * { public private *; }

SMS Retriever API is available in Google Play Services v10.2 and is used to auto-verify the OTP SMS.
https://developers.google.com/identity/sms-retriever/
This API will not be available in the devices that do not have Google Play Services installed - like Amazon Fire devices or the devices in the Chinese region.
If you are using this API, you have to check whether Play services are installed in the device before accessing this API.
Looking at your exception, it seems this API has been used by some Facebook kit.

Related

Unable to Start Activity... android.content.res.Resources$NotFoundException: Drawable com.app: drawable/abc_vector_test with resource ID #0x7f07005c

I´m trying to do an App that works with Firebase and authenticates with Google, Email and Facebook.
Is exactly in the phase of Facebook sync that I had this problem:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.aplicacintrabajandoenlanube, PID: 8112
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.aplicacintrabajandoenlanube/com.example.aplicacintrabajandoenlanube.LoginActivity}: android.content.res.Resources$NotFoundException: Drawable com.example.aplicacintrabajandoenlanube:drawable/abc_vector_test with resource ID #0x7f07005c
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: android.content.res.Resources$NotFoundException: Drawable com.example.aplicacintrabajandoenlanube:drawable/abc_vector_test with resource ID #0x7f07005c
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f07005c
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:891)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:673)
at android.content.res.Resources.loadDrawable(Resources.java:993)
at android.content.res.Resources.getDrawableForDensity(Resources.java:983)
at android.content.res.Resources.getDrawable(Resources.java:922)
at android.content.Context.getDrawable(Context.java:693)
at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:454)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:144)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:132)
at androidx.appcompat.widget.ResourceManagerInternal.checkVectorDrawableSetup(ResourceManagerInternal.java:504)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:137)
at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:411)
at androidx.appcompat.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:86)
at androidx.appcompat.app.AppCompatDelegateImpl.attachToWindow(AppCompatDelegateImpl.java:647)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureWindow(AppCompatDelegateImpl.java:623)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreate(AppCompatDelegateImpl.java:350)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:105)
at com.example.aplicacintrabajandoenlanube.LoginActivity.onCreate(LoginActivity.java:23)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from xml type drawable resource ID #0x7f07005c
at android.content.res.ResourcesImpl.loadXmlResourceParser(ResourcesImpl.java:1264)
at android.content.res.ResourcesImpl.loadXmlDrawable(ResourcesImpl.java:952)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:877)
... 32 more
Caused by: java.io.FileNotFoundException: res/drawable/abc_vector_test.xml
at android.content.res.AssetManager.nativeOpenXmlAsset(Native Method)
at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:1092)
at android.content.res.ResourcesImpl.loadXmlResourceParser(ResourcesImpl.java:1248)
... 34 more
Just so U know, my Gradle has a folder that says 6.5, which I think is the versión of Gradle.
PS: I´m literally a starter, so I do not understand most of the things I´m doing and probably will do, so please, help me in the easiest way possible (hahahah)
Analyzing the Stack Trace clearly I can depict that, It's causing an Runtime Exception since there is exactly no Resource found named drawable/abc_vector_test in your drawable folder.
Since Android didn't found the resource it's raising an Resource Not Found Exception. Kindly create the drawable file and then try running the app once.
For more information read the documentation here

RecyclerView and CoordinatorLayout with id are crashing

When I started writing nested fragments I encountered an unexpected problem. When the application is killed by Android, e.g. when there is a small amount of free RAM, the application throws the following exception after resuming it.
E/Parcel: Class not found when unmarshalling: android.support.design.widget.CoordinatorLayout$SavedState
java.lang.ClassNotFoundException: android.support.design.widget.CoordinatorLayout$SavedState
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:453)
at android.os.Parcel.readParcelableCreator(Parcel.java:2888)
at android.os.Parcel.readParcelable(Parcel.java:2842)
at android.os.Parcel.readValue(Parcel.java:2745)
at android.os.Parcel.readSparseArrayInternal(Parcel.java:3195)
at android.os.Parcel.readSparseArray(Parcel.java:2407)
at android.os.Parcel.readValue(Parcel.java:2802)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3114)
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:273)
at android.os.BaseBundle.unparcel(BaseBundle.java:226)
at android.os.BaseBundle.putBoolean(BaseBundle.java:532)
at android.support.v4.app.Fragment.setUserVisibleHint(Fragment.java:960)
at android.support.v4.app.FragmentStatePagerAdapter.instantiateItem(FragmentStatePagerAdapter.java:121)
at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1004)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1186)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1086)
at android.support.v4.view.ViewPager$3.run(ViewPager.java:267)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:655)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.ClassNotFoundException: android.support.design.widget.CoordinatorLayout$SavedState
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:1355)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:1415)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at java.lang.Class.classForName(Native Method) 
at java.lang.Class.forName(Class.java:453) 
at android.os.Parcel.readParcelableCreator(Parcel.java:2888) 
at android.os.Parcel.readParcelable(Parcel.java:2842) 
at android.os.Parcel.readValue(Parcel.java:2745) 
at android.os.Parcel.readSparseArrayInternal(Parcel.java:3195) 
at android.os.Parcel.readSparseArray(Parcel.java:2407) 
at android.os.Parcel.readValue(Parcel.java:2802) 
at android.os.Parcel.readArrayMapInternal(Parcel.java:3114) 
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:273) 
at android.os.BaseBundle.unparcel(BaseBundle.java:226) 
at android.os.BaseBundle.putBoolean(BaseBundle.java:532) 
at android.support.v4.app.Fragment.setUserVisibleHint(Fragment.java:960) 
at android.support.v4.app.FragmentStatePagerAdapter.instantiateItem(FragmentStatePagerAdapter.java:121) 
at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1004) 
at android.support.v4.view.ViewPager.populate(ViewPager.java:1186) 
at android.support.v4.view.ViewPager.populate(ViewPager.java:1086) 
at android.support.v4.view.ViewPager$3.run(ViewPager.java:267) 
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911) 
at android.view.Choreographer.doCallbacks(Choreographer.java:723) 
at android.view.Choreographer.doFrame(Choreographer.java:655) 
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897) 
at android.os.Handler.handleCallback(Handler.java:790) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6494) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
android.os.BadParcelableException: ClassNotFoundException when unmarshalling: android.support.design.widget.CoordinatorLayout$SavedState
at android.os.Parcel.readParcelableCreator(Parcel.java:2916)
at android.os.Parcel.readParcelable(Parcel.java:2842)
at android.os.Parcel.readValue(Parcel.java:2745)
at android.os.Parcel.readSparseArrayInternal(Parcel.java:3195)
at android.os.Parcel.readSparseArray(Parcel.java:2407)
at android.os.Parcel.readValue(Parcel.java:2802)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3114)
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:273)
at android.os.BaseBundle.unparcel(BaseBundle.java:226)
at android.os.BaseBundle.putBoolean(BaseBundle.java:532)
at android.support.v4.app.Fragment.setUserVisibleHint(Fragment.java:960)
at android.support.v4.app.FragmentStatePagerAdapter.instantiateItem(FragmentStatePagerAdapter.java:121)
at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1004)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1186)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1086)
at android.support.v4.view.ViewPager$3.run(ViewPager.java:267)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:655)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
This error occurs only if RecyclerView or CoordinatorLayout in tab fragment are assigned in xml android id.
In order to identify the error, I wrote an application in which I reproduced it.
https://github.com/RicomenPL/SampleBPE
How to reproduce it?
Enable "dont keep activies" in the development options on the smartphone or emulator
Turn on the SampleBPE application
Move to tabs left or right
Now you have to leave with the Home key
Enter again with the use of the recent apps key
Moving the tabs to the left or right will cause an error
The problem was solved when I downgrade my support libraries to version 26.1.0. This is a temporary solution, to avoid the problem. I hope that in version 28, this will be resolved.

java.lang.NoSuchFieldError: No static field KL of type Lcom/google/android/gms/internal/zzsb$zzb

I'm trying to open a Camera Activity on my Android but I got this error when the Activity starts:
FATAL EXCEPTION: main
Process: bookreader.bookreader, PID: 19132
java.lang.NoSuchFieldError: No static field KL of type Lcom/google/android/gms/internal/zzsb$zzb; in class Lcom/google/android/gms/internal/zzsb; or its superclasses (declaration of 'com.google.android.gms.internal.zzsb' appears in /data/app/bookreader.bookreader-1/split_lib_dependencies_apk.apk:classes4.dex)
at com.google.android.gms.vision.text.internal.client.zze.zzcic(Unknown Source)
at com.google.android.gms.vision.text.internal.client.zze.<init>(Unknown Source)
at com.google.android.gms.vision.text.TextRecognizer$Builder.build(Unknown Source)
at bookreader.bookreader.CameraActivity.onCreate(CameraActivity.java:97)
at android.app.Activity.performCreate(Activity.java:6609)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3113)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3275)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1744)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:7007)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
I don't know how to solve it. In my Android Manifest, I have this:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
make sure everything is up to date inside your build.gradle
no such method/field/class error usually occur because of dependency version mismatch (obfuscated fields names may be different across versions)

Android + jfreeSVG: inheritance issues

I'm developing and Android App with Android Studio. This app makes use of an all-java library module. I've included jfreesvg by adding compile 'org.jfree:jfreesvg:3.1' to the dependencies of said java library module.
Within that java library, I am trying the given example from the main doc for SVGGraphics2D:
SVGGraphics2D g2 = new SVGGraphics2D(300, 200);
g2.setPaint(Color.black);
g2.draw(new Rectangle(10, 10, 280, 180));
String svgElement = g2.getSVGElement();
However, I get two compile errors in Android Studio, the first being in the second line:
setPaint(java.awt.Paint) in SVGGraphics2D cannot be applied to (java.awt.Color)
Also, in the next line, the following error with, I suppose the same cause, occurrs: draw(java.awt.Paint) in SVGGraphics2D cannot be applied to (java.awt.Color)
My question now is: Even though java.awt.Paint is an Interface and java.awt.Color is an implementation of that interface, why do I get that error (and the same for java.awt.Shape and java.awt.Rectangle)?
For the sake of completion: If I do run the app, which I'm confused about that it works, I get the following Exception:
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: [package].app, PID: 19596
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:811)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jfree/graphics2d/svg/SVGGraphics2D;
at [package].[some.package].someMethod(Unknown)
at [package].app.MainActivity$SomeTask.doInBackground(MainActivity.java:67)
at [package].app.MainActivity$SomeTask.doInBackground(MainActivity.java:62)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
at java.lang.Thread.run(Thread.java:811) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jfree.graphics2d.svg.SVGGraphics2D" on path: DexPathList[[zip file "/data/app/[package].app-2.apk"],nativeLibraryDirectories=[/data/app-lib/[package].app-2, /system/lib, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at [package].[some.package].someMethod(Unknown) 
at [package].app.MainActivity$SomeTask.doInBackground(MainActivity.java:67) 
at [package].app.MainActivity$SomeTask.doInBackground(MainActivity.java:62) 
at android.os.AsyncTask$2.call(AsyncTask.java:288) 
at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
at java.lang.Thread.run(Thread.java:811) 
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/Graphics2D;
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:222)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:215)
at dalvik.system.DexPathList.findClass(DexPathList.java:322)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
... 11 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.awt.Graphics2D" on path: DexPathList[[zip file "/data/app/[package].app-2.apk"],nativeLibraryDirectories=[/data/app-lib/[package].app-2, /system/lib, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 16 more
Suppressed: java.lang.ClassNotFoundException: java.awt.Graphics2D
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 17 more
Caused by: java.lang.NoClassDefFoundError: Class "Ljava/awt/Graphics2D;" not found
... 21 more
Suppressed: java.lang.ClassNotFoundException: org.jfree.graphics2d.svg.SVGGraphics2D
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 10 more
Caused by: java.lang.NoClassDefFoundError: Class "Lorg/jfree/graphics2d/svg/SVGGraphics2D;" not found
... 14 more
(I edited the stack trace for better readability.)
The java.awt.* package is not available in Android. So the library that you are trying to use cannot be used directly in your Android app. At least not without further work.
You would need to implement those classes yourself, or source them from somewhere else, such as from the Apache Harmony project.

Java 7 platform independent Base64?

I am trying to make an app that will work on multiple platforms including android. The problem I'm having is that my sun.misc.BASE64Decoder works on the app running on the computer:
BASE64Decoder decoder = new BASE64Decoder();
byte[] data = decoder.decodeBuffer(is);
It's not working on an android device:
E/AndroidRuntime(18172): java.lang.NoClassDefFoundError: Failed resolution of: Lsun/misc/BASE64Decoder;
E/AndroidRuntime(18172): at com.company.app.backend.SomeClass$1.run(SomeClass.java:55)
E/AndroidRuntime(18172): at java.lang.Thread.run(Thread.java:818)
E/AndroidRuntime(18172): Caused by: java.lang.ClassNotFoundException: Didn't find class "sun.misc.BASE64Decoder" on path: DexPathList[[zip file "/data/app/com.company.app-1/base.apk"],nativeLibraryDirectories=[/data/app/com.company.app-1/lib/arm, /vendor/lib, /system/lib]]
E/AndroidRuntime(18172): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(18172): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime(18172): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime(18172): ... 2 more
E/AndroidRuntime(18172): Suppressed: java.lang.ClassNotFoundException: sun.misc.BASE64Decoder
E/AndroidRuntime(18172): at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(18172): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime(18172): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime(18172): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime(18172): ... 3 more
E/AndroidRuntime(18172): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Unfortunately I can not use Java 8's java.util.Base64 because I can't use Java 8. Also I can not use android.util.Base64 since it will not work outside of android.
I will appreciate any help.
If you can use third party libraries, you can use commons-codec.
If not, you can find plenty of pure Java implementations online. Even the Wikipedia article has a code sample. Just add it to your own utility class.

Categories