React Native Android Crash: java.lang.NoClassDefFoundError - android

I just recently launched my React Native Android app into production and a bunch of users are experiencing the following crash:
java.lang.NoClassDefFoundError
I'm not sure how to go about debugging this. I can't seem to reproduce it locally on any of my physical devices, and because it's Java and not JavaScript, I'm a bit unfamiliar. It looks like these users are all on Android 4.x, could that have something to do with it?
If you could help point me in the right direction, I would really appreciate it!

I had the same issue that i was not able to reproduce but i get the following error in a simulator Android 4.4
I'm not sure if it's android vitals that just return a partial error or if it's actually not the same error.
java.lang.RuntimeException:
Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException
E/AndroidRuntime( 3446): at android.app.ActivityThread.installProvider(ActivityThread.java:4793)
E/AndroidRuntime( 3446): at android.app.ActivityThread.installContentProviders(ActivityThread.java:4385)
E/AndroidRuntime( 3446): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4325)
E/AndroidRuntime( 3446): at android.app.ActivityThread.access$1500(ActivityThread.java:135)
E/AndroidRuntime( 3446): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
E/AndroidRuntime( 3446): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 3446): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 3446): at android.app.ActivityThread.main(ActivityThread.java:5017)
E/AndroidRuntime( 3446): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3446): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 3446): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime( 3446): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime( 3446): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 3446): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider"
E/AndroidRuntime( 3446): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime( 3446): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
E/AndroidRuntime( 3446): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
E/AndroidRuntime( 3446): at android.app.ActivityThread.installProvider(ActivityThread.java:4778)
E/AndroidRuntime( 3446): ... 12 more
This error was making the app crash on startup
I was able to fix it with this answer : https://stackoverflow.com/a/37317943/11170097
Use Multidex.
in your app/build.gradle
android {
...
defaultConfig {
....
multiDexEnabled true
}
...
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
...
}
in your app/src/main/java/.../MainApplication.java
...
import android.support.multidex.MultiDex;
import android.content.Context;
public class MyApplication extends ... {
...
#Override
protected void attachBaseContext(Context context) {
super.attachBaseContext(context);
MultiDex.install(this);
}
}

I have currently encountered this issue at my project. The root cause of this issue is the unavailability of certain classes at specific API level.
For my case, I used RoleManager which is only available since API 29. Even I added a runtime checking like:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// Use `RoleManager` ...
}
The above line of codes are run smoothly in Native Android project but React Native throws me the error. This is actually caused by the line of import !
import android.app.role.RoleManager
Although I cannot find any RN official documentation about this phenomenon at the moment, I believe RN checks if all imports are valid before running developer's codes! Therefore, it is a totally different idea with Native Android programming flow!
Solution could be moving everything you're using into a Util.java / Util.kt and complete you logic in another class!

Related

Android adb log - Collecting recent log after application crashes

Keywords: android, log, adb
My problem is after long runnning time, my application crashes while resumes. This bug crashes abnormaly, so I cannot collect it at that time.
Right after my application crashes, I want to collect recent log of my application so I can find out the bug. How can I do it?
Any suggestion may help, thanks.
I see at least to ways to do it:
Crashlytics
To collect crash reports, I advise you to use Crashlytics. Made by Twitter, easy to maintain and use.
Here you would find more info:
https://fabric.io/kits/android/crashlytics/summary
http://try.crashlytics.com/sdk-android/
It has also an Android Studio & IntelliJ Idea plugins.
Firebase Crash Reporting
You can also use introduced by Google new Fibase feature called Firebase Crash Reporting. Check: https://firebase.google.com/docs/crash/
I've already used the first solution and I'm pretty sure that you would love this.
The answer of piotrek1543 is great.
I just add this as an situational option:
After your app crashes, there is a chance that your phone still have that log. If that is the case, you can connect your phone with usb cable then use adb shell to fetch it:
adb shell "logcat your.app.package:W -v long | grep E/AndroidRuntime" > android.log
E/AndroidRuntime is a key filter for android runtime error log, change it as you want. You will get something like:
E/AndroidRuntime( 2494): FATAL EXCEPTION: main
E/AndroidRuntime( 2494): Process: your.app.package, PID: 2494
E/AndroidRuntime( 2494): java.lang.RuntimeException: MainActivity btn_throwException
E/AndroidRuntime( 2494): at your.app.package.MainActivity$2.onClick(MainActivity.java:35)
E/AndroidRuntime( 2494): at android.view.View.performClick(View.java:4463)
E/AndroidRuntime( 2494): at android.view.View$PerformClick.run(View.java:18770)
E/AndroidRuntime( 2494): at android.os.Handler.handleCallback(Handler.java:808)
E/AndroidRuntime( 2494): at android.os.Handler.dispatchMessage(Handler.java:103)
E/AndroidRuntime( 2494): at android.os.Looper.loop(Looper.java:193)
E/AndroidRuntime( 2494): at android.app.ActivityThread.main(ActivityThread.java:5323)
E/AndroidRuntime( 2494): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2494): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 2494): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
E/AndroidRuntime( 2494): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
E/AndroidRuntime( 2494): at dalvik.system.NativeStart.main(Native Method)
see more here https://developer.android.com/studio/command-line/logcat.html

Unable to instantiate application - java.lang.ClassNotFoundException: Didn't find class "com.xxxxx.App" on path: /data/app/com.xxxxx-1.apk

This is the error everytime I run the app:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate application com.xxxxx.App: java.lang.ClassNotFoundException: Didn't find class "com.xxxxx.App" on path: /data/app/com.xxxxx-1.apk
at android.app.LoadedApk.makeApplication(LoadedApk.java:509)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4657)
at android.app.ActivityThread.access$1400(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1376)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.xxxxx.App" on path: /data/app/com.xxxxx-1.apk
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:64)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newApplication(Instrumentation.java:992)
at android.app.LoadedApk.makeApplication(LoadedApk.java:504)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4657) 
at android.app.ActivityThread.access$1400(ActivityThread.java:159) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1376) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:176) 
at android.app.ActivityThread.main(ActivityThread.java:5419) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862) 
at dalvik.system.NativeStart.main(Native Method)
Here some info:
JavaVersion.VERSION_1_8 (I cannot use 1.7 because of a library)
buildToolsVersion '24.0.0'
compileSdkVersion & target 24 (also tried 23)
gradle 2.2.0-alpha4 (also tried with 2.1.0)
I have instant run disabled.
I have a class named App that extends Application, so in AndroidManifest.xml I have <application android:name="com.xxxxx.App"
Please don't mark this question as duplicate, because I have already tried all the solutions given, but I cannot get rid of this error.
 
I was having the same error and just cleaning the project solve it for me.
it seems a bug in the new version of android studio.
remove the app from your mobile phone then build => clean project and try installing again
Have you tried running the app on another device/emulator?
I experienced this problem once because I was the 2nd user on the device that I was trying to run it on. If that's the case, you will have to switch to the primary user(owner) every time you wish to run your app.
I was having the same issue, then tried creating the same application class in java instead of kotlin and it worked.

Android Studio 0.8.2: project using an sdk add-on which provides a jar library

I am trying to build a SDK add-on so developpers can use our library. I started by using this sample (a jar library add-on containing a system service):
https://github.com/gibsson/basic_sdk_addon
https://github.com/gibsson/BasicService
https://github.com/gibsson/BasicClient
I have followed the instructions from BasicService and BasicClient github pages and successfully created a working image by building both applications with the AOSP (for Android 4.3).
I built the two packages by adding the following to the device.mk file:
PRODUCT_PACKAGES += \
com.gibsson.basic.service.lib \
com.gibsson.basic.service.lib.xml \
BasicServiceApp \
BasicClient
This way, everything was build in the image and working.
End of introduction
I removed the BasicClient package from the build process and I am trying to bring this client in Android Studio, with the SDK, as would Android developpers do (they don't have access to the AOSP)
The basic_sdk_addon was successfuly created by following the instructions and using this command:
AOSP$ make PRODUCT-basic_sdk_addon-sdk_addon
I installed the Add-on in Android Studio using a User-defined repo. In the BasicClient project, I had to manually add the .jar file to the app/libs folder and click "Add as library" in order to compile BasicClient properly.
When trying to run/debug the BasicClient from AndroidStudio, I get the following error (from logcat, it's more detailed):
I/ActivityManager( 2544): Start proc com.gibsson.basic.client for activity com.gibsson.basic.client/.BasicActivity: pid=3311 uid=10044 gids={50044, 1015, 1028}
W/dalvikvm( 3311): Class resolved by unexpected DEX: Lcom/gibsson/basic/client/BasicActivity;(0x4213e238):0x40030000 ref [Lcom/gibsson/basic/service/lib/BasicManager;] Lcom/gibsson/basic/service/lib/BasicManager;(0x4213e238):0x4001d000
W/dalvikvm( 3311): (Lcom/gibsson/basic/client/BasicActivity; had used a different Lcom/gibsson/basic/service/lib/BasicManager; during pre-verification)
D/AndroidRuntime( 3311): Shutting down VM
W/dalvikvm( 3311): threadid=1: thread exiting with uncaught exception (group=0x41891700)
E/AndroidRuntime( 3311): FATAL EXCEPTION: main
E/AndroidRuntime( 3311): java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
E/AndroidRuntime( 3311): at com.gibsson.basic.client.BasicActivity.<init>(BasicActivity.java:18)
E/AndroidRuntime( 3311): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime( 3311): at java.lang.Class.newInstance(Class.java:1130)
E/AndroidRuntime( 3311): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
E/AndroidRuntime( 3311): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
E/AndroidRuntime( 3311): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
E/AndroidRuntime( 3311): at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime( 3311): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
E/AndroidRuntime( 3311): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 3311): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 3311): at android.app.ActivityThread.main(ActivityThread.java:5103)
E/AndroidRuntime( 3311): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3311): at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime( 3311): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
E/AndroidRuntime( 3311): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime( 3311): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 2544): Force finishing activity com.gibsson.basic.client/.BasicActivity
I understand that there is a mismatch between the BasicManager dex file found and what it expects. I verified if the tools used where the same version between the AOSP and Android Studio: both use the same JDK (1.6.0.45) and the same compile version (18).
Got it working: it seems that importing the BasicService Eclipse project modified the Dependencies scope drop down menu (in Project Structure). I can now choose Provided instead of Compile, and the application works perfectly.
When creating a new project from scratch, I only had the following choices: Compile, Runtime.
So I've looked at the differences between the two projects and the build.gradle file was the only one that was changed: compile was replaced by provided.
dependencies {
provided files('libs/com.orthogone.canvas.service.lib.jar')
}
There seems to be a bug in the UI, as the Dependencies Dialog doesn't provide this choice even with the build.gradle modification.
Another important note: the AndroidManifest.xml must contain the <uses-library> information in the <appliation> section:
<uses-library
android:name="com.gibsson.basic.service.lib"
android:required="true" />

GenyMotion 4.3 Image fails to launch application

I have updated to Genymotion 2.0 and downloaded/deployed the new 4.3 images (Galaxy Nexus and 10.1 Tablet) upon installing the appropriate GApps package get a devastating error upon launching a development app with the following stack trace making the device restart.
I/Process ( 3117): Sending signal. PID: 3117 SIG: 9
E/AndroidRuntime( 3117): *** FATAL EXCEPTION IN SYSTEM PROCESS: android.server.ServerThread
E/AndroidRuntime( 3117): java.lang.IllegalArgumentException: provider doesn't exisit: null
E/AndroidRuntime( 3117): at com.android.server.LocationManagerService.requestLocationUpdatesLocked(LocationManagerService.java:1323)
E/AndroidRuntime( 3117): at com.android.server.LocationManagerService.requestLocationUpdates(LocationManagerService.java:1302)
E/AndroidRuntime( 3117): at android.location.LocationManager.requestLocationUpdates(LocationManager.java:836)
E/AndroidRuntime( 3117): at android.location.LocationManager.requestLocationUpdates(LocationManager.java:461)
E/AndroidRuntime( 3117): at com.android.location.fused.FusionEngine.enableProvider(FusionEngine.java:138)
E/AndroidRuntime( 3117): at com.android.location.fused.FusionEngine.updateRequirements(FusionEngine.java:191)
E/AndroidRuntime( 3117): at com.android.location.fused.FusionEngine.setRequest(FusionEngine.java:114)
E/AndroidRuntime( 3117): at com.android.location.fused.FusedLocationProvider$2.handleMessage(FusedLocationProvider.java:98)
E/AndroidRuntime( 3117): at androi
For what I know the last update to Genymotion removed the support for google apps and google-play-service from it's images because of some disagreement with Google, you can read more about it here:
https://plus.google.com/+GenymotionEmulator/posts/jNF8Kwu5p1c
So from now on, you can't run Google Maps API V2 applications and use other features of the google-play-service like the LocationManager you are trying to use.
UPDATE:
As mentioned in the comments you could install the GApps package manually using the following guide:
http://blog.zeezonline.com/2013/11/install-google-play-on-genymotion-2-0/

Overriding WebSettings cordovaExample.java leads to errors in PhoneGap

This should really be easy for an experienced android programmer. Unfortunately I don't know anything about the android sdk. I am using PhoneGap to package a web app and I need to override the WebSettings in the cordovaExample.java (right now I am using the cordovaExample as a template for my app). My code looks like this:
package org.apache.cordova.example;
import android.app.Activity;
import android.os.Bundle;
import org.apache.cordova.*;
public class cordovaExample extends DroidGap
{
#Override
public void onCreate(Bundle savedInstanceState)
{
this.appView.getSettings().setUseWideViewPort(true);
this.appView.getSettings().setLoadWithOverviewMode(true);
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}
I can run ant debug install without a problem but when I start the app in the emulator, the following errors occur:
E/AndroidRuntime( 549): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.apache.cordova.example/org.apache.cordova.example.cordovaExample}: java.lang.NullPointerException
E/AndroidRuntime( 549): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
E/AndroidRuntime( 549): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
E/AndroidRuntime( 549): at android.app.ActivityThread.access$600(ActivityThread.java:123)
E/AndroidRuntime( 549): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
E/AndroidRuntime( 549): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 549): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 549): at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime( 549): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 549): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 549): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime( 549): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime( 549): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 549): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 549): at org.apache.cordova.example.cordovaExample.onCreate(cordovaExample.java:12)
E/AndroidRuntime( 549): at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime( 549): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime( 549): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
E/AndroidRuntime( 549): ... 11 more
W/ActivityManager( 78): Force finishing activity org.apache.cordova.example/.cordovaExample
The errors occur no matter if I package for android sdk 2.1 or 4.3 (on Mac OS X Lion).
Any help will be very much appreciated.
The error says that there is a NullPointerException at line 12:
this.appView.getSettings().setUseWideViewPort(true);
Either this.appView is null of appView.getSettings() is returning null. Add null value checks and see which one it is. It will be easier to find out why there is a null value there once you know which one it is.
Also, nothing to do with the problem and not sure if it is a typo but your class name is camel cased. It is against best practice to do that. It will confuse you in the future to do that since camel case nomenclature is used with instance variables, members, and methods only. Class names are always Initial letter uppercased and package names are always lowercase.
So it should be
CordovaExample
and not
cordovaExample
appView is null ... call super.onCreate(savedInstanceState); first
This was the solution for me when you want the browser to scale the viewport to the device width no matter the pixel width of the device:
Add these lines after super.loadURL(...):
super.appView.getSettings().setLoadWithOverviewMode(true);
super.appView.getSettings().setUseWideViewPort(true);
... in combination with meta viewport attributes that allow for scaling.

Categories

Resources